Project overview

The goal of the Pyromania project is to test how terrestrial subsides (plant biomass loading or “browning”) and burning influence aquatic productivity, water quality/chemistry, and trophic transfer. We used a manipulative experiment to assess a range of plant material quantities (0-400g per tank) and fire treatment (burned vs unburned material) and the non-linearity of these effects on aquatic systems through 4 time-point samplings. We used 400L aquatic mesocosms and ran the experiment for ~90d in 2021-2022.

Figure 1. Pyromania experimental setup

DATA SETS
This data set is among 3 to be generated for the project and focuses on:

  1. dissolved organic carbon (DOC) concentrations
  2. total dissolved nitrogen (TDN) concentrations
  3. net primary productivity and respiration (NPP, R) using whole mesocosm dissolved oxygen (O2) measurements
  4. burning effects on donor plant material using elemental analysis
  5. greenhouse gas concentrations (carbon dioxide (CO2), methane (CH4)) from mesocosms
  6. trophic transfer using 15N-labeled sage plants to trace N from the plants into plankton.

TIME POINTS

  • Time-0 (T0) = before the addition of plant materials, plankton were stocked at this stage
  • Time-1 (T1) = 10 days after the addition of plant materials
  • Time-2 (T2) = 31 days after …
  • Time-3 (T3) = 59 days after …
  • Time-4 (T4) = 89 days after …

General notes on GAM analyses
We fit the generalized additive models (GAMs) via restricted maximum likelihood (REML) to give stable results with the smoothing parameter (sp) to determine the non-linear relationship between response variables and plant-biomass loading (x-axis). We use automatic smoothing with k value generated automatically from the models, which will set the line ‘wiggliness’. Too low and the relationship becomes linear; too high, and the wiggliness goes haywire.

When using the non-linear smoothing, this is the s(x). When the variable is inside the smooth function, this accounts for the nonlinear shape. We do not use additive non-linear smoothing, which is when two smoothers together, as s(x1) + s(x2), instead we use factor-smooth interaction (detailed below). In addition, we use Treatment (and occasionally plankton size fractions, or Type) as predictors outside of the smooth terms s(x1); this allows for linearity. Continuous variables are rarely linear in GAMs, however, setting categorical variables as linear predictors is more common.

Factor-smooth interactions are written as s(x1 by = fac). This sets different smoothers for different variables of “fac”. Usually, the different smoothers are combined with a varying intercept in case the different categories are different in means and slopes, this would be by adding the fac + s(x1 by = fac), where the +fac allows for a different slope. Similarly, in the absence of by = fac, the smoother is considered a global smoother s(x1), fitting a single line to all the data. If a global smoother is combined with a factor term, then this is akin to varying the intercept but keeping the same slope: fac + s(x1).

The EDF - effective degrees of freedom equate with wiggliness, where edf =1 is a straight line, and higher edfs as more wiggly. GAM smoother significance is described as not being able to draw a horizontal line through the data. Finally, it is also advised to check model concurvity, which is the collinearity with models from 0-1.

DOC

Import the data for DOC and TDN and do a loop to clean up all files and make stacked data in single df. This will take the raw data files, align metadata, and filter to make a new df for models. Analyze DOC at each time point. Run model selection and produce plots for each individual timepoint, later pooled into a 5 panel figure.

detach("package:dplyr", unload = TRUE)
library(dplyr)

## import treatment IDs
IDs<-read.csv("data/treatment.IDs.csv")

##### grab files in a list
Total.DOC.files <- list.files(path="data/DOC.TN", pattern = "csv$", full.names = T)

##### what are the file names, sans extensions using package 'tools'
file.names<-file_path_sans_ext(list.files(path="data/DOC.TN", pattern = "csv$", full.names = F))
############ formatting all data in for loop
  for(i in 1:length(Total.DOC.files))
    {
  data<-read.csv(Total.DOC.files[i], sep=",")
  data<-data[,c(1:3)] # only keep these columns
  data$File<-Total.DOC.files[i]
  colnames(data)<-c("Tank", "DOC..mg.L", "TN..mg.L", "File")
  data$Tank<- IDs$Tank
  data$Tank<-as.numeric(as.character(data$Tank)) # make the column of samples all numeric
  data <- data[!is.na(as.numeric(as.character(data$Tank))),] # remove all rows that aren't numeric/tanks
  data$Treatment<-IDs$Treatment
  data$plant.mass..g<-IDs$plant.mass..g
  make.names(assign(paste(file.names[i], sep=""), data)) # make the file name the name of new df for loop df
  }
########## this is the end of the loop

#see all dfs you've made, the above will be df matching their file names
# ls() 

#Combine files from loop to single df
DOC.df<-rbind(DOC_T0, DOC_T1, DOC_T2, DOC_T3, DOC_T4)

DOC.df$File <- sapply(strsplit(DOC.df$File, "/"), `[`, 3) # extract sample names

# alternative way to code the above
#give the 10th-24th character of the file name, removing the rest
#DOC.df$File<-substr(DOC.df$File, 13, 27) 

#alternatively
# remove the 9 letters ('^.) at start 
# remove the 4 letters (.$') at end
#DOC.df$File<-gsub('^.........|....$', '', DOC.df$File) 

# if equals DOC_T0_11052021 then, T0, if not then T1
DOC.df$Time.point<- as.factor(ifelse(DOC.df$File=="DOC_T0.csv", "T0",
         ifelse (DOC.df$File=="DOC_T1.csv", "T1",
           ifelse (DOC.df$File=="DOC_T2.csv", "T2", 
                   ifelse(DOC.df$File=="DOC_T3.csv", "T3", "T4")))))

#rearrange
DOC.df<- DOC.df %>% 
  select(File, Time.point, Treatment, Tank, plant.mass..g, DOC..mg.L, TN..mg.L) 

DOC.df$Treatment<-as.factor(DOC.df$Treatment)

######## T0 model
m1.DOC.T0<-gam(DOC..mg.L ~ Treatment + s(plant.mass..g, by= Treatment), subset = Time.point=="T0", data = DOC.df, method = "REML")

m2.DOC.T0<-gam(DOC..mg.L ~  Treatment + s(plant.mass..g), subset = Time.point=="T0", data = DOC.df, method = "REML")

m3.DOC.T0<-gam(DOC..mg.L ~  s(plant.mass..g), subset = Time.point=="T0", data = DOC.df, method = "REML")

T0.DOC.AIC<-AIC(m1.DOC.T0, m2.DOC.T0, m3.DOC.T0)
# best is smoother solo

summary(m3.DOC.T0)
anova.gam(m3.DOC.T0)
gam.check(m3.DOC.T0, rep=1000)
draw(m3.DOC.T0)
concrvity(m3.DOC.T0)
par(mfrow = c(2, 2))
plot(m3.DOC.T0, all.terms = TRUE, page=1)

# model predictions
DOC.diff.T0<-plot_difference(
  m1.DOC.T0,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
#plot for the model output on rawdata
DOC.T0.mod.plot<-
  plot_smooths(
  model = m3.DOC.T0,
  series = plant.mass..g,
) + 
  geom_point(data=DOC.df[(DOC.df$Time.point=="T0"),], 
             aes(x=plant.mass..g, y=DOC..mg.L, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) + 
  coord_cartesian(ylim=c(0, 60)) +
  ggtitle("Day-0") +
  ylab("DOC (mg/L)") +
  xlab("plant material (g)") +
  Fig.formatting


######## T1 model
m1.DOC.T1<-gam(DOC..mg.L ~ Treatment + s(plant.mass..g, by= Treatment), subset = Time.point=="T1", data = DOC.df, method = "REML")

m2.DOC.T1<-gam(DOC..mg.L ~  Treatment + s(plant.mass..g), subset = Time.point=="T1", data = DOC.df, method = "REML")

m3.DOC.T1<-gam(DOC..mg.L ~  s(plant.mass..g), subset = Time.point=="T1", data = DOC.df, method = "REML")

T1.DOC.AIC<-AIC(m1.DOC.T1, m2.DOC.T1, m3.DOC.T1)
# best is smooth by factor

summary(m1.DOC.T1)
anova.gam(m1.DOC.T1)
gam.check(m1.DOC.T1, rep=1000)
draw(m1.DOC.T1)
concrvity(m1.DOC.T1)
par(mfrow = c(2, 2))
plot(m1.DOC.T1, all.terms = TRUE, page=1)

# model predictions
DOC.diff.T1<-plot_difference(
  m1.DOC.T1,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
#plot for the model output on rawdata
DOC.T1.mod.plot<-
  plot_smooths(
  model = m1.DOC.T1,
  series = plant.mass..g,
  comparison = Treatment
) + 
  geom_point(data=DOC.df[(DOC.df$Time.point=="T1"),], 
             aes(x=plant.mass..g, y=DOC..mg.L, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) + 
  coord_cartesian(ylim=c(0, 60)) +
  ggtitle("Day-10") +
  ylab("DOC (mg/L)") +
  xlab("plant material (g)") +
  Fig.formatting


# effect of treatment, smoothing significant across both treatments
# DOC higher in  unburned, relative to burned


########## T2
m1.DOC.T2<-gam(DOC..mg.L ~ Treatment + s(plant.mass..g, by= Treatment), subset = Time.point=="T2", data = DOC.df, method = "REML")

m2.DOC.T2<-gam(DOC..mg.L ~  Treatment + s(plant.mass..g), subset = Time.point=="T2", data = DOC.df, method = "REML")

m3.DOC.T2<-gam(DOC..mg.L ~  s(plant.mass..g), subset = Time.point=="T2", data = DOC.df, method = "REML")

T2.DOC.AIC<-AIC(m1.DOC.T2, m2.DOC.T2, m3.DOC.T2)

# best is smooth by factor

summary(m1.DOC.T2)
anova.gam(m1.DOC.T2)
gam.check(m1.DOC.T2, rep=1000)
draw(m1.DOC.T2)
concrvity(m1.DOC.T2)
par(mfrow = c(2, 2))
plot(m1.DOC.T2, all.terms = TRUE, page=1)

# model predictions
DOC.diff.T2<-plot_difference(
  m1.DOC.T2,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
#plot for the model output on rawdata
DOC.T2.mod.plot<-
  plot_smooths(
  model = m1.DOC.T2,
  series = plant.mass..g,
  comparison = Treatment
) + 
  geom_point(data=DOC.df[(DOC.df$Time.point=="T2"),], 
             aes(x=plant.mass..g, y=DOC..mg.L, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) + 
  coord_cartesian(ylim=c(0, 60)) +
  ggtitle("Day-31") +
  ylab("DOC (mg/L)") +
  xlab("plant material (g)") +
  Fig.formatting

# NO effect of treatment, smoothing significant across both treatments
# DOC equivalent in burned and unburned 
# DOC more variable/wonky across gradient in burned


########## T3
m1.DOC.T3<-gam(DOC..mg.L ~ Treatment + s(plant.mass..g, by= Treatment), subset = Time.point=="T3", data = DOC.df, method = "REML")

m2.DOC.T3<-gam(DOC..mg.L ~  Treatment + s(plant.mass..g), subset = Time.point=="T3", data = DOC.df, method = "REML")

m3.DOC.T3<-gam(DOC..mg.L ~  s(plant.mass..g), subset = Time.point=="T3", data = DOC.df, method = "REML")

T3.DOC.AIC<-AIC(m1.DOC.T3, m2.DOC.T3, m3.DOC.T3)
# best by factor smooth

summary(m1.DOC.T3)
anova.gam(m1.DOC.T3)
gam.check(m1.DOC.T3, rep=1000)
draw(m1.DOC.T3)
concrvity(m1.DOC.T3)
par(mfrow = c(2, 2))
plot(m1.DOC.T3, all.terms = TRUE, page=1)

# model predictions
DOC.diff.T3<-plot_difference(
  m1.DOC.T3,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
#plot for the model output on rawdata
DOC.T3.mod.plot<-
  plot_smooths(
  model = m1.DOC.T3,
  series = plant.mass..g,
  comparison = Treatment
) + 
  geom_point(data=DOC.df[(DOC.df$Time.point=="T3"),], 
             aes(x=plant.mass..g, y=DOC..mg.L, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) + 
  coord_cartesian(ylim=c(0, 60)) +
  ggtitle("Day-59") +
  ylab("DOC (mg/L)") +
  xlab("plant material (g)") +
  Fig.formatting

# effect of treatment, smoothing significant across both treatments
# DOC higher in  burned vs. unburned


########## T4
m1.DOC.T4<-gam(DOC..mg.L ~ Treatment + s(plant.mass..g, by= Treatment), subset = Time.point=="T4", data = DOC.df, method = "REML")

m2.DOC.T4<-gam(DOC..mg.L ~  Treatment + s(plant.mass..g), subset = Time.point=="T4", data = DOC.df, method = "REML")

m3.DOC.T4<-gam(DOC..mg.L ~  s(plant.mass..g), subset = Time.point=="T4", data = DOC.df, method = "REML")

T4.DOC.AIC<-AIC(m1.DOC.T4, m2.DOC.T4, m3.DOC.T4)

# best is global
summary(m3.DOC.T4)
anova.gam(m3.DOC.T4)
gam.check(m3.DOC.T4, rep=1000)
draw(m3.DOC.T4)
concrvity(m3.DOC.T4)
par(mfrow = c(2, 2))
plot(m3.DOC.T4, all.terms = TRUE, page=1)

# model predictions
DOC.diff.T4<-plot_difference(
  m1.DOC.T4,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
#plot for the model output on rawdata
DOC.T4.mod.plot<-
  plot_smooths(
  model = m3.DOC.T4,
  series = plant.mass..g
) + 
  geom_point(data=DOC.df[(DOC.df$Time.point=="T4"),], 
             aes(x=plant.mass..g, y=DOC..mg.L, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) + 
  coord_cartesian(ylim=c(0, 60)) +
  ggtitle("Day-89") +
  ylab("DOC (mg/L)") +
  xlab("plant material (g)") +
  Fig.formatting

# no effect of treatment, smoothing significant across both treatments
# DOC equivalent in  burned and unburned


mod.rep<-rep(c("~Treatment + s(plant.mass..g, by= Treatment)", 
              "~Treatment + s(plant.mass..g)", 
              "~s(plant.mass..g)"), times=5)

mod.DOC.df<- data.frame(mod.rep)

AIC.DOC<-bind_rows(T0.DOC.AIC, T1.DOC.AIC, T2.DOC.AIC, T3.DOC.AIC, T4.DOC.AIC)
AIC.DOC.mod<-cbind(mod.DOC.df, AIC.DOC)

write.csv(AIC.DOC.mod, "output/AIC models/AIC.DOC.csv")

DOC tables

Table: Results for DOC Time-0

anova.gam(m3.DOC.T0)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## DOC..mg.L ~ s(plant.mass..g)
## 
## Approximate significance of smooth terms:
##                   edf Ref.df     F p-value
## s(plant.mass..g) 1.04   1.08 1.341    0.24

Table: Results for DOC Time-1

anova.gam(m1.DOC.T2)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## DOC..mg.L ~ Treatment + s(plant.mass..g, by = Treatment)
## 
## Parametric Terms:
##           df     F p-value
## Treatment  1 0.035   0.853
## 
## Approximate significance of smooth terms:
##                                      edf Ref.df     F p-value
## s(plant.mass..g):Treatmentburned   6.482  7.532 34.39  <2e-16
## s(plant.mass..g):Treatmentunburned 1.568  1.929 59.34  <2e-16

Table: Results for DOC Time-2

anova.gam(m1.DOC.T2)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## DOC..mg.L ~ Treatment + s(plant.mass..g, by = Treatment)
## 
## Parametric Terms:
##           df     F p-value
## Treatment  1 0.035   0.853
## 
## Approximate significance of smooth terms:
##                                      edf Ref.df     F p-value
## s(plant.mass..g):Treatmentburned   6.482  7.532 34.39  <2e-16
## s(plant.mass..g):Treatmentunburned 1.568  1.929 59.34  <2e-16

Table: Results for DOC Time-3

anova.gam(m1.DOC.T3)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## DOC..mg.L ~ Treatment + s(plant.mass..g, by = Treatment)
## 
## Parametric Terms:
##           df     F p-value
## Treatment  1 12.32 0.00182
## 
## Approximate significance of smooth terms:
##                                      edf Ref.df     F p-value
## s(plant.mass..g):Treatmentburned   2.051  2.532 94.00  <2e-16
## s(plant.mass..g):Treatmentunburned 2.202  2.714 56.55  <2e-16

Table: Results for DOC Time-4

anova.gam(m3.DOC.T4)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## DOC..mg.L ~ s(plant.mass..g)
## 
## Approximate significance of smooth terms:
##                    edf Ref.df    F p-value
## s(plant.mass..g) 1.928  2.385 29.8  <2e-16

DOC figures

Compile raw plots and model-diff plots for final figures.

###### compile the plots with effect plots

extract.legend <- get_legend(
  # create some space to the left of the legend
  DOC.T1.mod.plot + theme(legend.box.margin = margin(0, 0, 0, 10)))


DOC.alltimes<-plot_grid(
  DOC.T0.mod.plot+ theme(legend.position = "none"),
  DOC.T1.mod.plot+ theme(legend.position = "none"),
  DOC.T2.mod.plot+ theme(legend.position = "none"),
  DOC.T3.mod.plot+ theme(legend.position = "none"),
  DOC.T4.mod.plot+ theme(legend.position = "none"), extract.legend,
  rel_widths = c(8,8,8,8,8,3), ncol=6)
ggsave("figures/DOC.alltimes.mod.pdf", height=4, width=15)

DOC.alltimes

Model differences between the two factor-smoothers. The areas in pink show where there are significant differences between the two smoothers, indicating treatment effects.

DOC.mod.diffs<-plot_grid(
  DOC.diff.T0+ theme(legend.position = "none")+ ggtitle("Day-0"),
  DOC.diff.T1+ theme(legend.position = "none")+ ggtitle("Day-10"),
  DOC.diff.T2+ theme(legend.position = "none")+ ggtitle("Day-31"),
  DOC.diff.T3+ theme(legend.position = "none")+ ggtitle("Day-59"),
  DOC.diff.T4+ theme(legend.position = "none")+ ggtitle("Day-89"),
  rel_widths = c(8,8,8,8,8), ncol=5)
ggsave("figures/DOC.mod.diffs.pdf", height=4, width=14)

DOC.mod.diffs

TDN

Using the above dataframes for DOC and TDN, analyze total N (total dissolved nitrogen (TDN)) and make plots in each timepoint, running models and making model-difference plots.

TN.df<-DOC.df

######## T0 model
m1.TN.T0<-gam(TN..mg.L ~ Treatment + s(plant.mass..g, by=Treatment), 
              subset = Time.point=="T0", data = TN.df, method = "REML")

m2.TN.T0<-gam(TN..mg.L ~ Treatment + s(plant.mass..g), 
              subset = Time.point=="T0", data = TN.df, method = "REML")

m3.TN.T0<-gam(TN..mg.L ~ s(plant.mass..g), 
              subset = Time.point=="T0", data = TN.df, method = "REML")

T0.TN.AIC<-AIC(m1.TN.T0, m2.TN.T0, m3.TN.T0)
# best smooth by factor

summary(m1.TN.T0)
anova.gam(m1.TN.T0)
gam.check(m1.TN.T0, rep=1000)
draw(m1.TN.T0)
concrvity(m1.TN.T0)
par(mfrow = c(2, 2))
plot(m1.TN.T0, all.terms = TRUE, page=1)

# model predictions
TN.diff.T0<-plot_difference(
  m1.TN.T0,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

## plot for the model output on rawdata
TN.T0.mod.plot<-
  plot_smooths(
  model = m1.TN.T0,
  series = plant.mass..g,
  comparison = Treatment
) + 
  geom_point(data=TN.df[(TN.df$Time.point=="T0"),], 
             aes(x=plant.mass..g, y=TN..mg.L, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +  
  coord_cartesian(ylim=c(0, 2)) +
  ggtitle("Day-0") +
  ylab("TN (mg/L)")  +
  xlab("plant material (g)") +
  Fig.formatting

# no treatment effect, compare to simplified model (p=0.901)

######## T1 model
m1.TN.T1<-gam(TN..mg.L ~ Treatment + s(plant.mass..g, by=Treatment), 
              subset = Time.point=="T1", data = TN.df, method = "REML")

m2.TN.T1<-gam(TN..mg.L ~ Treatment + s(plant.mass..g), 
              subset = Time.point=="T1", data = TN.df, method = "REML")

m3.TN.T1<-gam(TN..mg.L ~ s(plant.mass..g), 
              subset = Time.point=="T1", data = TN.df, method = "REML")

T1.TN.AIC<-AIC(m1.TN.T1, m2.TN.T1, m3.TN.T1)
#best global only

summary(m3.TN.T1)
anova.gam(m3.TN.T1)
gam.check(m3.TN.T1, rep=1000)
draw(m3.TN.T1)
concrvity(m3.TN.T1)
par(mfrow = c(2, 2))
plot(m3.TN.T1, all.terms = TRUE, page=1)

# model predictions
TN.diff.T1<-plot_difference(
  m1.TN.T1,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

## plot for the model output on rawdata
TN.T1.mod.plot<-
  plot_smooths(
  model = m3.TN.T1,
  series = plant.mass..g
) + 
  geom_point(data=TN.df[(TN.df$Time.point=="T1"),], 
             aes(x=plant.mass..g, y=TN..mg.L, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +  
  coord_cartesian(ylim=c(0, 2)) +
  ggtitle("Day-10") +
  ylab("TN (mg/L)")  +
  xlab("plant material (g)") +
  Fig.formatting

# TN smoother significant for unburned but not burned (p=0.007)


######## T2 model
m1.TN.T2<-gam(TN..mg.L ~ Treatment + s(plant.mass..g, by=Treatment), 
              subset = Time.point=="T2", data = TN.df, method = "REML")

m2.TN.T2<-gam(TN..mg.L ~ Treatment + s(plant.mass..g), 
              subset = Time.point=="T2", data = TN.df, method = "REML")

m3.TN.T2<-gam(TN..mg.L ~ s(plant.mass..g), 
              subset = Time.point=="T2", data = TN.df, method = "REML")

T2.TN.AIC<-AIC(m1.TN.T2, m2.TN.T2, m3.TN.T2)
#best global with treatment term

summary(m2.TN.T2)
anova.gam(m2.TN.T2)
gam.check(m2.TN.T2, rep=1000)
draw(m2.TN.T2)
concrvity(m2.TN.T2)
par(mfrow = c(2, 2))
plot(m2.TN.T2, all.terms = TRUE, page=1)

# model predictions
TN.diff.T2<-plot_difference(
  m1.TN.T2,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

## plot for the model output on rawdata
TN.T2.mod.plot<-
  plot_smooths(
  model = m2.TN.T2,
  series = plant.mass..g,
  comparison=Treatment
) + 
  geom_point(data=TN.df[(TN.df$Time.point=="T2"),], 
             aes(x=plant.mass..g, y=TN..mg.L, color=Treatment)) +
  geom_line(aes(fill=Treatment, linetype=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +  
  coord_cartesian(ylim=c(0, 2)) +
  ggtitle("Day-31") +
  ylab("TN (mg/L)")  +
  xlab("plant material (g)") +
  Fig.formatting

# Near treatment effect p=0.053, higher TN in unburned
# smoother signif: 0.042


######## T3 model
m1.TN.T3<-gam(TN..mg.L ~ Treatment + s(plant.mass..g, by=Treatment), 
              subset = Time.point=="T3", data = TN.df, method = "REML")

m2.TN.T3<-gam(TN..mg.L ~ Treatment + s(plant.mass..g), 
              subset = Time.point=="T3", data = TN.df, method = "REML")

m3.TN.T3<-gam(TN..mg.L ~ s(plant.mass..g), 
              subset = Time.point=="T3", data = TN.df, method = "REML")

T3.TN.AIC<-AIC(m1.TN.T3, m2.TN.T3, m3.TN.T3)
#best with smooth by factor term

summary(m1.TN.T3)
anova.gam(m1.TN.T3)
gam.check(m1.TN.T3, rep=1000)
draw(m1.TN.T3)
concrvity(m1.TN.T3)
par(mfrow = c(2, 2))
plot(m1.TN.T3, all.terms = TRUE, page=1)

# model predictions
TN.diff.T3<-plot_difference(
  m1.TN.T3,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

## plot for the model output on rawdata
TN.T3.mod.plot<-
  plot_smooths(
  model = m1.TN.T3,
  series = plant.mass..g,
  comparison = Treatment
) + 
  geom_point(data=TN.df[(TN.df$Time.point=="T3"),], 
             aes(x=plant.mass..g, y=TN..mg.L, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +  
  coord_cartesian(ylim=c(0, 2)) +
  ggtitle("Day-59") +
  ylab("TN (mg/L)")  +
  xlab("plant material (g)") +
  Fig.formatting

# Near treatment effect p=0.075, trend for higher TN in burned
# smoother signif: at <0.001 for both


######## T4 model
m1.TN.T4<-gam(TN..mg.L ~ Treatment + s(plant.mass..g, by=Treatment), 
              subset = Time.point=="T4", data = TN.df, method = "REML")

m2.TN.T4<-gam(TN..mg.L ~ Treatment + s(plant.mass..g), 
              subset = Time.point=="T4", data = TN.df, method = "REML")

m3.TN.T4<-gam(TN..mg.L ~ s(plant.mass..g), 
              subset = Time.point=="T4", data = TN.df, method = "REML")

T4.TN.AIC<-AIC(m1.TN.T4, m2.TN.T4, m3.TN.T4)
#best  with smooth by factor term

summary(m1.TN.T4)
anova.gam(m1.TN.T4)
gam.check(m1.TN.T4, rep=1000)
draw(m1.TN.T4)
concrvity(m1.TN.T4)
par(mfrow = c(2, 2))
plot(m1.TN.T4, all.terms = TRUE, page=1)

# model predictions
TN.diff.T4<-plot_difference(
  m1.TN.T4,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

## plot for the model output on rawdata
TN.T4.mod.plot<-
  plot_smooths(
  model = m1.TN.T4,
  series = plant.mass..g,
  comparison = Treatment
) + 
  geom_point(data=TN.df[(TN.df$Time.point=="T4"),], 
             aes(x=plant.mass..g, y=TN..mg.L, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +  
  coord_cartesian(ylim=c(0, 2)) +
  ggtitle("Day-89") +
  ylab("TN (mg/L)")  +
  xlab("plant material (g)") +
  Fig.formatting


# effect of treatment (higher TN in the burned) (p=0.020)
# significant smoother effect for burned treatment only (p=0.032)

mod.rep<-rep(c("~Treatment + s(plant.mass..g, by= Treatment)", 
              "~Treatment + s(plant.mass..g)", 
              "~s(plant.mass..g)"), times=5)

mod.TN.df<- data.frame(mod.rep)

AIC.TN<-bind_rows(T0.TN.AIC, T1.TN.AIC, T2.TN.AIC, T3.TN.AIC, T4.TN.AIC)
AIC.TN.mod<-cbind(mod.TN.df, AIC.TN)
write.csv(AIC.TN.mod, "output/AIC models/AIC.TN.mod.csv")

TDN tables

Results for TDN Time-0

anova.gam(m1.TN.T0)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## TN..mg.L ~ Treatment + s(plant.mass..g, by = Treatment)
## 
## Parametric Terms:
##           df     F p-value
## Treatment  1 0.879   0.357
## 
## Approximate significance of smooth terms:
##                                    edf Ref.df     F p-value
## s(plant.mass..g):Treatmentburned     1      1 0.009  0.9266
## s(plant.mass..g):Treatmentunburned   1      1 6.303  0.0186

Table: Results for TDN Time-1

anova.gam(m3.TN.T1)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## TN..mg.L ~ s(plant.mass..g)
## 
## Approximate significance of smooth terms:
##                    edf Ref.df    F p-value
## s(plant.mass..g) 2.848  3.492 5.72 0.00274

Table: Results for TDN Time-2

anova.gam(m2.TN.T2)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## TN..mg.L ~ Treatment + s(plant.mass..g)
## 
## Parametric Terms:
##           df     F p-value
## Treatment  1 4.122  0.0532
## 
## Approximate significance of smooth terms:
##                    edf Ref.df    F p-value
## s(plant.mass..g) 3.207  3.921 4.87 0.00425

Table: Results for TDN Time-3

anova.gam(m1.TN.T3)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## TN..mg.L ~ Treatment + s(plant.mass..g, by = Treatment)
## 
## Parametric Terms:
##           df   F p-value
## Treatment  1 3.5  0.0752
## 
## Approximate significance of smooth terms:
##                                      edf Ref.df     F  p-value
## s(plant.mass..g):Treatmentburned   4.359  5.269 23.03  < 2e-16
## s(plant.mass..g):Treatmentunburned 2.457  3.022 10.52 0.000194

Table: Results for TDN Time-4

anova.gam(m1.TN.T4)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## TN..mg.L ~ Treatment + s(plant.mass..g, by = Treatment)
## 
## Parametric Terms:
##           df     F p-value
## Treatment  1 6.231  0.0196
## 
## Approximate significance of smooth terms:
##                                      edf Ref.df     F p-value
## s(plant.mass..g):Treatmentburned   2.417  2.973 3.613  0.0318
## s(plant.mass..g):Treatmentunburned 1.000  1.000 0.531  0.4731

TDN figures

Compile raw plots and model-diff plots for final figures.

###### compile the plots with effect plots

TN.mod.alltimes<-plot_grid(
  TN.T0.mod.plot+ theme(legend.position = "none"), 
  TN.T1.mod.plot+ theme(legend.position = "none"),
  TN.T2.mod.plot+ theme(legend.position = "none"),
  TN.T3.mod.plot+ theme(legend.position = "none"),
  TN.T4.mod.plot+ theme(legend.position = "none"), extract.legend,
  rel_widths = c(8,8,8,8,8,3), ncol=6)
ggsave("figures/TN.mods.plots.pdf", height=4, width=13)

TN.mod.alltimes

Model differences between the two factor-smoothers. The areas in pink show where there are significant differences between the two smoothers, indicating treatment effects.

TN.mod.diffs<-plot_grid(
  TN.diff.T0+ theme(legend.position = "none")+ ggtitle("Day-0"),
  TN.diff.T1+ theme(legend.position = "none")+ ggtitle("Day-10"),
  TN.diff.T2+ theme(legend.position = "none")+ ggtitle("Day-31"),
  TN.diff.T3+ theme(legend.position = "none")+ ggtitle("Day-59"),
  TN.diff.T4+ theme(legend.position = "none")+ ggtitle("Day-89"),
  rel_widths = c(8,8,8,8,8,3), ncol=6)
ggsave("figures/TN.mod.diffs.pdf", height=4, width=13)

TN.mod.diffs

YSI

Import YSI data and produce plots of changes in O2% and net primary productivity (NPP) and respiration (R). The YSI data includes Temp, pH, dissolved oxygen (percent and concentration), and conductivity. Here, we will pull in the raw data and make the new metrics NPP and R, determined from differences in DO% from dawn-dusk (NPP) and dusk-dawn (R) over a 24h period in each time period.

#load YSI data
YSI<-read.csv("data/Pyro_YSI.csv")

# fix date
YSI$Date<-as.character(YSI$Date)
YSI$Date<-as.POSIXct(YSI$Date, format="%m/%d/%Y")
YSI$Date<-as.Date(YSI$Date, format="%m/%d/%Y")


####### Time 1 change in O2 ################

#separate time points
YSI.T1<- YSI[(YSI$Time.point=="T1"),]

#calculate NPP for T1
T1.Prod<-YSI.T1[(YSI.T1$Date == "2021-11-15"),] # dawn and dusk for 12h period
T1.Dawn1<-T1.Prod[(T1.Prod$Dawn..Dusk == "dawn"),] # dawn-1 measurements
T1.Dusk<-T1.Prod[(T1.Prod$Dawn..Dusk == "dusk"),] # dusk measurements

T1.Dawn2<-YSI.T1[(YSI.T1$Date == "2021-11-16"),] # dawn-2 measurements, following AM

# make new dataframe
T1.O2<-(T1.Dawn1[,c(2,4:6)]) 
T1.O2$dawn1<-T1.Dawn1$DO.percent
T1.O2$dusk1<-T1.Dusk$DO.percent
T1.O2$dawn2<-T1.Dawn2$DO.percent

# R = dusk - dawn (PM to AM, O2 change of day 1)
# NPP = dusk - dawn (PM to AM, O2 change of day 2)

T1.O2<- mutate(T1.O2, 
                NPP=dusk1 - dawn1,
                R=dawn2 - dusk1) 

#sort
T1.O2<-T1.O2 %>% 
  arrange(Treatment, plant.mass..g) 


################ ################ ################
####### Time 2 change in O2 ################

#separate time points
YSI.T2<- YSI[(YSI$Time.point=="T2"),]

#calculate NPP for T2
T2.Prod<-YSI.T2[(YSI.T2$Date == "2021-12-06"),] # dawn and dusk for 12h period
T2.Dawn1<-T2.Prod[(T2.Prod$Dawn..Dusk == "dawn"),] # dawn-1 measurements
T2.Dusk<-T2.Prod[(T2.Prod$Dawn..Dusk == "dusk"),] # dusk measurements

T2.Dawn2<-YSI.T2[(YSI.T2$Date == "2021-12-07"),] # dawn-2 measurements, following AM

# make new dataframe
T2.O2<-(T2.Dawn1[,c(2,4:6)]) 
T2.O2$dawn1<-T2.Dawn1$DO.percent
T2.O2$dusk1<-T2.Dusk$DO.percent
T2.O2$dawn2<-T2.Dawn2$DO.percent

T2.O2<- mutate(T2.O2, 
                NPP=dusk1 - dawn1,
                R=dawn2 - dusk1) 

#sort
T2.O2<-T2.O2 %>% 
  arrange(Treatment, plant.mass..g) 


################ ################ ################
####### Time 3 change in O2 ################

#separate time points
YSI.T3<- YSI[(YSI$Time.point=="T3"),]

#calculate NPP for T3
T3.Prod<-YSI.T3[(YSI.T3$Date == "2022-01-03"),] # dawn and dusk for 12h period
T3.Dawn1<-T3.Prod[(T3.Prod$Dawn..Dusk == "dawn"),] # dawn-1 measurements
T3.Dusk<-T3.Prod[(T3.Prod$Dawn..Dusk == "dusk"),] # dusk measurements

T3.Dawn2<-YSI.T3[(YSI.T3$Date == "2022-01-04"),] # dawn-2 measurements, following AM

# make new dataframe
T3.O2<-(T3.Dawn1[,c(2,4:6)]) 
T3.O2$dawn1<-T3.Dawn1$DO.percent
T3.O2$dusk1<-T3.Dusk$DO.percent
T3.O2$dawn2<-T3.Dawn2$DO.percent

T3.O2<- mutate(T3.O2, 
                NPP=dusk1 - dawn1,
                R=dawn2 - dusk1) 

#sort
T3.O2<-T3.O2 %>% 
  arrange(Treatment, plant.mass..g) 

################ ################ ################
####### Time 3 change in O2 ################

#separate time points
YSI.T4<- YSI[(YSI$Time.point=="T4"),]

#calculate NPP for T4
T4.Prod<-YSI.T4[(YSI.T4$Date == "2022-02-02"),] # dawn and dusk for 12h period
T4.Dawn1<-T4.Prod[(T4.Prod$Dawn..Dusk == "dawn"),] # dawn-1 measurements
T4.Dusk<-T4.Prod[(T4.Prod$Dawn..Dusk == "dusk"),] # dusk measurements

T4.Dawn2<-YSI.T4[(YSI.T4$Date == "2022-02-03"),] # dawn-2 measurements, following AM

# make new dataframe
T4.O2<-(T4.Dawn1[,c(2,4:6)]) 
T4.O2$dawn1<-T4.Dawn1$DO.percent
T4.O2$dusk1<-T4.Dusk$DO.percent
T4.O2$dawn2<-T4.Dawn2$DO.percent

T4.O2<- mutate(T4.O2, 
                NPP=dusk1 - dawn1,
                R=dawn2 - dusk1) 

#sort
T4.O2<-T4.O2 %>% 
  arrange(Treatment, plant.mass..g) 

################ ################ ################
# combine T1  T2  T3 T4 timepoints
################ ################ ################
O2.tanks<-rbind(T1.O2,T2.O2, T3.O2, T4.O2)

cols<-c("Time.point", "Treatment", "Tank") # columns to make factors
O2.tanks[cols] <- lapply(O2.tanks[cols], factor) # make all these factors
O2.tanks$plant.mass..g<-as.numeric(O2.tanks$plant.mass..g)

DO and O2%

First, we will also run model fitting on the raw DO% data to apply the same approach for visualizing changes in oxygen across dawn-dusk-dawn measurements. We will then combine all these plots into multi-panel figures for NPP and R, and DO% for each point of measurement.

TIME POINT 1: Change in O2% from dissolved oxygen

#########################################################
##################################################################
# total oxygen % plot for the 3 time points (dawn-dusk-dawn)

m1.dawn1.T1<-gam(dawn1 ~ Treatment + s(plant.mass..g, by= Treatment), subset = Time.point=="T1", data = O2.tanks, method = "REML")

m2.dawn1.T1<-gam(dawn1 ~ Treatment + s(plant.mass..g), subset = Time.point=="T1", data = O2.tanks, method = "REML")

m3.dawn1.T1<-gam(dawn1 ~ s(plant.mass..g), subset = Time.point=="T1", data = O2.tanks, method = "REML")

T1.dawn1.AIC<-AIC(m1.dawn1.T1, m2.dawn1.T1, m3.dawn1.T1)
# global with treatment best


summary(m2.dawn1.T1)
anova.gam(m2.dawn1.T1)
gam.check(m2.dawn1.T1, rep=1000)
draw(m2.dawn1.T1)
concrvity(m2.dawn1.T1)
par(mfrow = c(2, 2))
plot(m2.dawn1.T1, all.terms = TRUE, page=1)

# model predictions
dawn1.diff.T1<-plot_difference(
  m1.dawn1.T1,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
#plot for the model output on rawdata
dawn1.T1.mod.plot<-
  plot_smooths(
  model = m2.dawn1.T1,
  series = plant.mass..g,
  comparison=Treatment
) + 
  geom_point(data=T1.O2, aes(x=plant.mass..g, y=dawn1, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +
  geom_line(aes(fill=Treatment, linetype=Treatment)) +
  geom_hline(yintercept=0, linetype="longdash", color = "gray") +
  ggtitle("T1.dawn1")+
  coord_cartesian(ylim=c(-30, 150)) +
  ylab(expression(paste("O"[2],"%"))) +
  xlab("plant material (g)") +
  theme(legend.position = "right") +
  Fig.formatting
  
# treatment (p=0.0279) and smoothers significant (p<0.001)

  
####### #### Dusk 1 
m1.dusk1.T1<-gam(dusk1 ~ Treatment + s(plant.mass..g, by= Treatment), subset = Time.point=="T1", data = O2.tanks, method = "REML")

m2.dusk1.T1<-gam(dusk1 ~ Treatment + s(plant.mass..g), subset = Time.point=="T1", data = O2.tanks, method = "REML")

m3.dusk1.T1<-gam(dusk1 ~ s(plant.mass..g), subset = Time.point=="T1", data = O2.tanks, method = "REML")

T1.dusk1.AIC<-AIC(m1.dusk1.T1, m2.dusk1.T1, m3.dusk1.T1)
# model with treatment and global smooth best

summary(m2.dusk1.T1)
anova.gam(m2.dusk1.T1)
gam.check(m2.dusk1.T1, rep=1000)
draw(m2.dusk1.T1)
concrvity(m2.dusk1.T1)
par(mfrow = c(2, 2))
plot(m2.dusk1.T1, all.terms = TRUE, page=1)

# model predictions
dusk1.diff.T1<-plot_difference(
  m1.dusk1.T1,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
#plot for the model output on rawdata
dusk1.T1.mod.plot<-
  plot_smooths(
  model = m2.dusk1.T1,
  series = plant.mass..g,
  comparison= Treatment
) + 
  geom_point(data=T1.O2, aes(x=plant.mass..g, y=dusk1, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +
  geom_line(aes(fill=Treatment, linetype=Treatment)) +
  geom_hline(yintercept=0, linetype="longdash", color = "gray") +
  ggtitle("T1.dusk1")+
  coord_cartesian(ylim=c(-30, 150)) +
  ylab(expression(paste("O"[2],"%"))) +
  xlab("plant material (g)") +
  theme(legend.position = "right") +
  Fig.formatting

# smoother significant for both treatments 


####### #### Dawn 2
m1.dawn2.T1<-gam(dawn2 ~ Treatment + s(plant.mass..g, by= Treatment), subset = Time.point=="T1", data = O2.tanks, method = "REML")

m2.dawn2.T1<-gam(dawn2 ~ Treatment + s(plant.mass..g), subset = Time.point=="T1", data = O2.tanks, method = "REML")

m3.dawn2.T1<-gam(dawn2 ~ s(plant.mass..g), subset = Time.point=="T1", data = O2.tanks, method = "REML")

T1.dawn2.AIC<-AIC(m1.dawn2.T1, m2.dawn2.T1, m3.dawn2.T1)
# treatment and global smooth best

summary(m2.dawn2.T1)
anova.gam(m2.dawn2.T1)
gam.check(m2.dawn2.T1, rep=1000)
draw(m2.dawn2.T1)
concrvity(m2.dawn2.T1)
par(mfrow = c(2, 2))
plot(m2.dawn2.T1, all.terms = TRUE, page=1)

# model predictions
dawn2.diff.T1<-plot_difference(
  m1.dawn2.T1,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned")),
)

###########  
#plot for the model output on rawdata
dawn2.T1.mod.plot<-
  plot_smooths(
  model = m2.dawn2.T1,
  series = plant.mass..g,
  comparison=Treatment
) + 
  geom_point(data=T1.O2, aes(x=plant.mass..g, y=dawn2, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +
  geom_line(aes(fill=Treatment, linetype=Treatment)) +
  geom_hline(yintercept=0, linetype="longdash", color = "gray") +
  
  ggtitle("T1.dawn2")+
  coord_cartesian(ylim=c(-30, 150)) +
  ylab(expression(paste("O"[2],"%"))) +
  xlab("plant material (g)") +
  theme(legend.position = "right") +
  Fig.formatting

# smoother significant for both (p<0.001)

#### group plots
O2.T1<-plot_grid(
  dawn1.T1.mod.plot+ theme(legend.position = "none"), 
  dusk1.T1.mod.plot+ theme(legend.position = "none"),
  dawn2.T1.mod.plot+ theme(legend.position = "none"),
  extract.legend, 
  rel_widths = c(8,8,8,3), ncol=4)

TIME POINT 2: Change in O2% from dissolved oxygen

############################################################
##############################################################################
# total oxygen % plot for the 3 time points (dawn-dusk-dawn)

m1.dawn1.T2<-gam(dawn1 ~ Treatment + s(plant.mass..g, by= Treatment), subset = Time.point=="T2", data = O2.tanks, method = "REML")

m2.dawn1.T2<-gam(dawn1 ~ Treatment + s(plant.mass..g), subset = Time.point=="T2", data = O2.tanks, method = "REML")

m3.dawn1.T2<-gam(dawn1 ~ s(plant.mass..g), subset = Time.point=="T2", data = O2.tanks, method = "REML")

T2.dawn1.AIC<-AIC(m1.dawn1.T2, m2.dawn1.T2, m3.dawn1.T2)
# factor by smooth best


summary(m1.dawn1.T2)
anova.gam(m1.dawn1.T2)
gam.check(m1.dawn1.T2, rep=1000)
draw(m1.dawn1.T2)
concrvity(m1.dawn1.T2)
par(mfrow = c(2, 2))
plot(m1.dawn1.T2, all.terms = TRUE, page=1)

# model predictions
dawn1.diff.T2<-plot_difference(
  m1.dawn1.T2,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
#plot for the model output on rawdata
dawn1.T2.mod.plot<-
  plot_smooths(
  model = m1.dawn1.T2,
  series = plant.mass..g,
  comparison = Treatment
) + 
  geom_point(data=T2.O2, aes(x=plant.mass..g, y=dawn1, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +
  geom_hline(yintercept=0, linetype="longdash", color = "gray") +
  ggtitle("T2.dawn1")+
  coord_cartesian(ylim=c(-30, 150)) +
  ylab(expression(paste("O"[2],"%"))) +
  xlab("plant material (g)") +
  theme(legend.position = "right") +
  Fig.formatting
  
# smoothers significant (p<0.001)

  
####### #### Dusk 1 
m1.dusk1.T2<-gam(dusk1 ~ Treatment + s(plant.mass..g, by= Treatment), subset = Time.point=="T2", data = O2.tanks, method = "REML")

m2.dusk1.T2<-gam(dusk1 ~ Treatment + s(plant.mass..g), subset = Time.point=="T2", data = O2.tanks, method = "REML")

m3.dusk1.T2<-gam(dusk1 ~ s(plant.mass..g), subset = Time.point=="T2", data = O2.tanks, method = "REML")

T2.dusk1.AIC<-AIC(m1.dusk1.T2, m2.dusk1.T2, m3.dusk1.T2)
# model with smooth by factor best

summary(m1.dusk1.T2)
anova.gam(m1.dusk1.T2)
gam.check(m1.dusk1.T2, rep=1000)
draw(m1.dusk1.T2)
concrvity(m1.dusk1.T2)
par(mfrow = c(2, 2))
plot(m1.dusk1.T2, all.terms = TRUE, page=1)

# model predictions
dusk1.diff.T2<-plot_difference(
  m1.dusk1.T2,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
#plot for the model output on rawdata
dusk1.T2.mod.plot<-
  plot_smooths(
  model = m1.dusk1.T2,
  series = plant.mass..g,
  comparison = Treatment
) + 
  geom_point(data=T2.O2, aes(x=plant.mass..g, y=dusk1, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +
  geom_hline(yintercept=0, linetype="longdash", color = "gray") +
  ggtitle("T2.dusk1")+
  coord_cartesian(ylim=c(-30, 150)) +
  ylab(expression(paste("O"[2],"%"))) +
  xlab("plant material (g)") +
  theme(legend.position = "right") +
  Fig.formatting

# smoother significant for both treatments 


####### #### Dawn 2
m1.dawn2.T2<-gam(dawn2 ~ Treatment + s(plant.mass..g, by= Treatment), subset = Time.point=="T2", data = O2.tanks, method = "REML")

m2.dawn2.T2<-gam(dawn2 ~ Treatment + s(plant.mass..g), subset = Time.point=="T2", data = O2.tanks, method = "REML")

m3.dawn2.T2<-gam(dawn2 ~ s(plant.mass..g), subset = Time.point=="T2", data = O2.tanks, method = "REML")

T2.dawn2.AIC<-AIC(m1.dawn2.T2, m2.dawn2.T2, m3.dawn2.T2)
# smooth by factor best

summary(m1.dawn2.T2)
anova.gam(m1.dawn2.T2)
gam.check(m1.dawn2.T2, rep=1000)
draw(m1.dawn2.T2)
concrvity(m1.dawn2.T2)
par(mfrow = c(2, 2))
plot(m1.dawn2.T2, all.terms = TRUE, page=1)

# model predictions
dawn2.diff.T2<-plot_difference(
  m1.dawn2.T2,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned")),
)

###########  
#plot for the model output on rawdata
dawn2.T2.mod.plot<-
  plot_smooths(
  model = m1.dawn2.T2,
  series = plant.mass..g,
  comparison=Treatment
) + 
  geom_point(data=T2.O2, aes(x=plant.mass..g, y=dawn2, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +
  geom_hline(yintercept=0, linetype="longdash", color = "gray") +
  ggtitle("T2.dawn2")+
  coord_cartesian(ylim=c(-30, 150)) +
  ylab(expression(paste("O"[2],"%"))) +
  xlab("plant material (g)") +
  theme(legend.position = "right") +
  Fig.formatting

# smoother significant for both (p<0.001)

#### group plots
O2.T2<-plot_grid(
  dawn1.T2.mod.plot+ theme(legend.position = "none"), 
  dusk1.T2.mod.plot+ theme(legend.position = "none"),
  dawn2.T2.mod.plot+ theme(legend.position = "none"),
  extract.legend, 
  rel_widths = c(8,8,8,3), ncol=4)

TIME POINT 3: Change in O2% from dissolved oxygen

############################################################
##############################################################################
#### Dawn1
m1.dawn1.T3<-gam(dawn1 ~ Treatment + s(plant.mass..g, by= Treatment), subset = Time.point=="T3", data = O2.tanks, method = "REML")

m2.dawn1.T3<-gam(dawn1 ~ Treatment + s(plant.mass..g), subset = Time.point=="T3", data = O2.tanks, method = "REML")

m3.dawn1.T3<-gam(dawn1 ~ s(plant.mass..g), subset = Time.point=="T3", data = O2.tanks, method = "REML")

T3.dawn1.AIC<-AIC(m1.dawn1.T3, m2.dawn1.T3, m3.dawn1.T3)
# factor by smooth best


summary(m1.dawn1.T3)
anova.gam(m1.dawn1.T3)
gam.check(m1.dawn1.T3, rep=1000)
draw(m1.dawn1.T3)
concrvity(m1.dawn1.T3)
par(mfrow = c(2, 2))
plot(m1.dawn1.T3, all.terms = TRUE, page=1)

# model predictions
dawn1.diff.T3<-plot_difference(
  m1.dawn1.T3,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
#plot for the model output on rawdata
dawn1.T3.mod.plot<-
  plot_smooths(
  model = m1.dawn1.T3,
  series = plant.mass..g,
  comparison = Treatment
) + 
  geom_point(data=T3.O2, aes(x=plant.mass..g, y=dawn1, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +
  geom_hline(yintercept=0, linetype="longdash", color = "gray") +
  ggtitle("T3.dawn1")+
  coord_cartesian(ylim=c(-30, 150)) +
  ylab(expression(paste("O"[2],"%"))) +
  xlab("plant material (g)") +
  theme(legend.position = "right") +
  Fig.formatting
  
# smoothers significant (p<0.001)

  
####### #### Dusk 1 
m1.dusk1.T3<-gam(dusk1 ~ Treatment + s(plant.mass..g, by= Treatment), subset = Time.point=="T3", data = O2.tanks, method = "REML")

m2.dusk1.T3<-gam(dusk1 ~ Treatment + s(plant.mass..g), subset = Time.point=="T3", data = O2.tanks, method = "REML")

m3.dusk1.T3<-gam(dusk1 ~ s(plant.mass..g), subset = Time.point=="T3", data = O2.tanks, method = "REML")

T3.dusk1.AIC<-AIC(m1.dusk1.T3, m2.dusk1.T3, m3.dusk1.T3)
# model with smooth by factor best

summary(m1.dusk1.T3)
anova.gam(m1.dusk1.T3)
gam.check(m1.dusk1.T3, rep=1000)
draw(m1.dusk1.T3)
concrvity(m1.dusk1.T3)
par(mfrow = c(2, 2))
plot(m1.dusk1.T3, all.terms = TRUE, page=1)

# model predictions
dusk1.diff.T3<-plot_difference(
  m1.dusk1.T3,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
#plot for the model output on rawdata
dusk1.T3.mod.plot<-
  plot_smooths(
  model = m1.dusk1.T3,
  series = plant.mass..g,
  comparison = Treatment
) + 
  geom_point(data=T3.O2, aes(x=plant.mass..g, y=dusk1, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +
  geom_hline(yintercept=0, linetype="longdash", color = "gray") +
  ggtitle("T3.dusk1")+
  coord_cartesian(ylim=c(-30, 150)) +
  ylab(expression(paste("O"[2],"%"))) +
  xlab("plant material (g)") +
  theme(legend.position = "right") +
  Fig.formatting

# no treatment effect
# smoother significant for burned 


####### #### Dawn 2
m1.dawn2.T3<-gam(dawn2 ~ Treatment + s(plant.mass..g, by= Treatment), subset = Time.point=="T3", data = O2.tanks, method = "REML")

m2.dawn2.T3<-gam(dawn2 ~ Treatment + s(plant.mass..g), subset = Time.point=="T3", data = O2.tanks, method = "REML")

m3.dawn2.T3<-gam(dawn2 ~ s(plant.mass..g), subset = Time.point=="T3", data = O2.tanks, method = "REML")

T3.dawn2.AIC<-AIC(m1.dawn2.T3, m2.dawn2.T3, m3.dawn2.T3)
# smooth by factor best

summary(m1.dawn2.T3)
anova.gam(m1.dawn2.T3)
gam.check(m1.dawn2.T3, rep=1000)
draw(m1.dawn2.T3)
concrvity(m1.dawn2.T3)
par(mfrow = c(2, 2))
plot(m1.dawn2.T3, all.terms = TRUE, page=1)

# model predictions
dawn2.diff.T3<-plot_difference(
  m1.dawn2.T3,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned")),
)

###########  
#plot for the model output on rawdata
dawn2.T3.mod.plot<-
  plot_smooths(
  model = m1.dawn2.T3,
  series = plant.mass..g,
  comparison=Treatment
) + 
  geom_point(data=T3.O2, aes(x=plant.mass..g, y=dawn2, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +
  geom_hline(yintercept=0, linetype="longdash", color = "gray") +
  ggtitle("T3.dawn2")+
  coord_cartesian(ylim=c(-30, 150)) +
  ylab(expression(paste("O"[2],"%"))) +
  xlab("plant material (g)") +
  theme(legend.position = "right") +
  Fig.formatting

# global smoother significant(p<0.001)

#### group plots
O2.T3<-plot_grid(
  dawn1.T3.mod.plot+ theme(legend.position = "none"), 
  dusk1.T3.mod.plot+ theme(legend.position = "none"),
  dawn2.T3.mod.plot+ theme(legend.position = "none"),
  extract.legend, 
  rel_widths = c(8,8,8,3), ncol=4)

TIME POINT 4: Change in O2% from dissolved oxygen

############################################################
##############################################################################
# total oxygen % plot for the 3 time points (dawn-dusk-dawn)

#### Dawn1
m1.dawn1.T4<-gam(dawn1 ~ Treatment + s(plant.mass..g, by= Treatment), subset = Time.point=="T4", data = O2.tanks, method = "REML")

m2.dawn1.T4<-gam(dawn1 ~ Treatment + s(plant.mass..g), subset = Time.point=="T4", data = O2.tanks, method = "REML")

m3.dawn1.T4<-gam(dawn1 ~ s(plant.mass..g), subset = Time.point=="T4", data = O2.tanks, method = "REML")

T4.dawn1.AIC<-AIC(m1.dawn1.T4, m2.dawn1.T4, m3.dawn1.T4)
# model with global best


summary(m3.dawn1.T4)
anova.gam(m3.dawn1.T4)
gam.check(m3.dawn1.T4, rep=1000)
draw(m3.dawn1.T4)
concrvity(m3.dawn1.T4)
par(mfrow = c(2, 2))
plot(m3.dawn1.T4, all.terms = TRUE, page=1)

# model predictions
dawn1.diff.T4<-plot_difference(
  m1.dawn1.T4,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
#plot for the model output on rawdata
dawn1.T4.mod.plot<-
  plot_smooths(
  model = m3.dawn1.T4,
  series = plant.mass..g,
) + 
  geom_point(data=T4.O2, aes(x=plant.mass..g, y=dawn1, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +
  geom_hline(yintercept=0, linetype="longdash", color = "gray") +
  ggtitle("T4.dawn1")+
  coord_cartesian(ylim=c(-30, 150)) +
  ylab(expression(paste("O"[2],"%"))) +
  xlab("plant material (g)") +
  theme(legend.position = "right") +
  Fig.formatting
  
# smoothers significant (p<0.001)

  
####### #### Dusk 1 
m1.dusk1.T4<-gam(dusk1 ~ Treatment + s(plant.mass..g, by= Treatment), subset = Time.point=="T4", data = O2.tanks, method = "REML")

m2.dusk1.T4<-gam(dusk1 ~ Treatment + s(plant.mass..g), subset = Time.point=="T4", data = O2.tanks, method = "REML")

m3.dusk1.T4<-gam(dusk1 ~ s(plant.mass..g), subset = Time.point=="T4", data = O2.tanks, method = "REML")

T4.dusk1.AIC<-AIC(m1.dusk1.T4, m2.dusk1.T4, m3.dusk1.T4)
# model with smooth by factor best

summary(m1.dusk1.T4)
anova.gam(m1.dusk1.T4)
gam.check(m1.dusk1.T4, rep=1000)
draw(m1.dusk1.T4)
concrvity(m1.dusk1.T4)
par(mfrow = c(2, 2))
plot(m1.dusk1.T4, all.terms = TRUE, page=1)

# model predictions
dusk1.diff.T4<-plot_difference(
  m1.dusk1.T4,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
#plot for the model output on rawdata
dusk1.T4.mod.plot<-
  plot_smooths(
  model = m1.dusk1.T4,
  series = plant.mass..g,
  comparison = Treatment
) + 
  geom_point(data=T4.O2, aes(x=plant.mass..g, y=dusk1, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +
  geom_hline(yintercept=0, linetype="longdash", color = "gray") +
  ggtitle("T4.dusk1")+
  coord_cartesian(ylim=c(-30, 150)) +
  ylab(expression(paste("O"[2],"%"))) +
  xlab("plant material (g)") +
  theme(legend.position = "right") +
  Fig.formatting

# no treatment effect
# smoother significant for burned 


####### #### Dawn 2
m1.dawn2.T4<-gam(dawn2 ~ Treatment + s(plant.mass..g, by= Treatment), subset = Time.point=="T4", data = O2.tanks, method = "REML")

m2.dawn2.T4<-gam(dawn2 ~ Treatment + s(plant.mass..g), subset = Time.point=="T4", data = O2.tanks, method = "REML")

m3.dawn2.T4<-gam(dawn2 ~ s(plant.mass..g), subset = Time.point=="T4", data = O2.tanks, method = "REML")

T4.dawn2.AIC<-AIC(m1.dawn2.T4, m2.dawn2.T4, m3.dawn2.T4)
# global smooth best

summary(m3.dawn2.T4)
anova.gam(m3.dawn2.T4)
gam.check(m3.dawn2.T4, rep=1000)
draw(m3.dawn2.T4)
concrvity(m3.dawn2.T4)
par(mfrow = c(2, 2))
plot(m3.dawn2.T4, all.terms = TRUE, page=1)

# model predictions
dawn2.diff.T4<-plot_difference(
  m1.dawn2.T4,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned")),
)

###########  
#plot for the model output on rawdata
dawn2.T4.mod.plot<-
  plot_smooths(
  model = m3.dawn2.T4,
  series = plant.mass..g,
) + 
  geom_point(data=T4.O2, aes(x=plant.mass..g, y=dawn2, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +
  geom_hline(yintercept=0, linetype="longdash", color = "gray") +
  ggtitle("T4.dawn2")+
  coord_cartesian(ylim=c(-30, 150)) +
  ylab(expression(paste("O"[2],"%"))) +
  xlab("plant material (g)") +
  theme(legend.position = "right") +
  Fig.formatting

# global smoother significant(p<0.001)

#### group plots
O2.T4<-plot_grid(
  dawn1.T4.mod.plot+ theme(legend.position = "none"), 
  dusk1.T4.mod.plot+ theme(legend.position = "none"),
  dawn2.T4.mod.plot+ theme(legend.position = "none"),
  extract.legend, 
  rel_widths = c(8,8,8,3), ncol=4)

Combine and export all the O2 data with plot-difference and model AIC tables


#### model differences
O2.mod.diffs<-plot_grid(
  dawn1.diff.T1+ theme(legend.position = "none")+ ggtitle("T1-Dawn1"),
  dusk1.diff.T1+ theme(legend.position = "none")+ ggtitle("Dusk1"),
  dawn2.diff.T1+ theme(legend.position = "none")+ ggtitle("Dawn2"),
  
  dawn1.diff.T2+ theme(legend.position = "none")+ ggtitle("T2-Dawn1"),
  dusk1.diff.T2+ theme(legend.position = "none")+ ggtitle("Dusk1"),
  dawn2.diff.T2+ theme(legend.position = "none")+ ggtitle("Dawn2"),
  
  dawn1.diff.T3+ theme(legend.position = "none")+ ggtitle("T3-Dawn1"),
  dusk1.diff.T3+ theme(legend.position = "none")+ ggtitle("Dusk1"),
  dawn2.diff.T3+ theme(legend.position = "none")+ ggtitle("Dawn2"),
  
  dawn1.diff.T4+ theme(legend.position = "none")+ ggtitle("T4-Dawn1"),
  dusk1.diff.T4+ theme(legend.position = "none")+ ggtitle("Dusk1"),
  dawn2.diff.T4+ theme(legend.position = "none")+ ggtitle("Dawn2"),
  rel_widths = c(8,8,8), ncol=3, nrow=4)

ggsave("figures/O2.mod.diffs.pdf", height=10, width=7)

#### model and raw data
O2.mods<-plot_grid(
  O2.T1+ theme(legend.position = "none")+ ggtitle("Day-10"),
  O2.T2+ theme(legend.position = "none")+ ggtitle("Day-31"),
  O2.T3+ theme(legend.position = "none")+ ggtitle("Day-59"),
  O2.T4+ theme(legend.position = "none")+ ggtitle("Day-89"),
  rel_widths = c(8,8,8,8), ncol=1, nrow=4)

ggsave("figures/O2.mod.pdf", height=11, width=9)
O2.mods

#bind the AIC tables
AIC.O2<-bind_rows(T1.dawn1.AIC, T1.dusk1.AIC, T1.dawn2.AIC,
                  T2.dawn1.AIC, T2.dusk1.AIC, T2.dawn2.AIC,
                  T3.dawn1.AIC, T3.dusk1.AIC, T3.dawn2.AIC,
                  T4.dawn1.AIC, T4.dusk1.AIC, T4.dawn2.AIC)

# make a model column
mod.rep12<-rep(c("~Treatment + s(plant.mass..g, by= Treatment)", 
              "~Treatment + s(plant.mass..g)", 
              "~s(plant.mass..g)"), times=12)

mod.O2.df<- data.frame(mod.rep12)
#bind table

AIC.O2.mod<-cbind(mod.O2.df, AIC.O2)

write.csv(AIC.O2.mod, "output/AIC models/AIC.O2.mod.csv")
**Figure.** Changes in dissolved oxygen concentration (%) at dawn and dusk across the four experimental period. Black lines with gray confidence intervals indicate global smoothers across all data points; solid (burned) and dotted (unburned) black lines together represent treatment-level intercepts with global smoothers; colored lines indicate factor-smooths that vary between treatments.

Figure. Changes in dissolved oxygen concentration (%) at dawn and dusk across the four experimental period. Black lines with gray confidence intervals indicate global smoothers across all data points; solid (burned) and dotted (unburned) black lines together represent treatment-level intercepts with global smoothers; colored lines indicate factor-smooths that vary between treatments.

NPP and R

Generate dataframes for NPP and R change in O2. We will use NPP and R, run gam model fits, and produce individual figures for each time point.

First, we will use NPP models for productivity measurements.

####### Time 1

m1.NPP.T1<-gam(NPP ~ Treatment + s(plant.mass..g, by= Treatment), subset = Time.point=="T1", data = O2.tanks, method = "REML")

m2.NPP.T1<-gam(NPP ~ Treatment + s(plant.mass..g), subset = Time.point=="T1", data = O2.tanks, method = "REML")

m3.NPP.T1<-gam(NPP ~ s(plant.mass..g), subset = Time.point=="T1", data = O2.tanks, method = "REML")

T1.NPP.AIC<-AIC(m1.NPP.T1, m2.NPP.T1, m3.NPP.T1)
# model with plot smooth by factor not different from reduced model, go with smooth by factor

summary(m2.NPP.T1)
anova.gam(m2.NPP.T1)
gam.check(m2.NPP.T1, rep=1000)
draw(m2.NPP.T1)
concrvity(m2.NPP.T1)
par(mfrow = c(2, 2))
plot(m2.NPP.T1, all.terms = TRUE, page=1)


#### see this https://cran.r-project.org/web/packages/tidymv/vignettes/plot-smooths.html
# The difference smooth is difference between the smooths of two conditions (two levels in a factor). 
# Portions of the difference smooth confidence interval that do not include 0 are shaded in red.

# model predictions
NPP.diff.T1<-plot_difference(
  m2.NPP.T1,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
#plot for the model output on rawdata
NPP.T1.mod.plot<-
  plot_smooths(
  model = m2.NPP.T1,
  series = plant.mass..g,
  comparison = Treatment
) + 
  geom_point(data=T1.O2, aes(x=plant.mass..g, y=NPP, color=Treatment)) +
  geom_line(aes(fill=Treatment, linetype=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) + 
  coord_cartesian(ylim=c(-20, 50)) +
  geom_hline(yintercept=0, linetype="longdash", color = "gray") +
  ylab(expression(paste("Net Production (", Delta, "O"[2],"%)"))) +
  theme(legend.position = "right") +
  Fig.formatting

# no treatment effect (p=0.110), smoothers significant (p<0.006)

####### Time 2

m1.NPP.T2<-gam(NPP ~ Treatment + s(plant.mass..g, by= Treatment), subset = Time.point=="T2", data = O2.tanks, method = "REML")

m2.NPP.T2<-gam(NPP ~ Treatment + s(plant.mass..g), subset = Time.point=="T2", data = O2.tanks, method = "REML")

m3.NPP.T2<-gam(NPP ~ s(plant.mass..g), subset = Time.point=="T2", data = O2.tanks, method = "REML")

T2.NPP.AIC<-AIC(m1.NPP.T2, m2.NPP.T2, m3.NPP.T2)
# model with plot smooth by factor not different from reduced model, go with smooth by factor


summary(m2.NPP.T2)
anova.gam(m2.NPP.T2)
gam.check(m2.NPP.T2, rep=1000)
draw(m2.NPP.T2)
concrvity(m2.NPP.T2)
par(mfrow = c(2, 2))
plot(m2.NPP.T2, all.terms = TRUE, page=1)

## plot for the model output on rawdata
# model predictions
NPP.diff.T2<-plot_difference(
  m2.NPP.T2,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

NPP.T2.mod.plot<-
  plot_smooths(
  model = m2.NPP.T2,
  series = plant.mass..g,
  comparison = Treatment
) + 
  geom_point(data=T2.O2, aes(x=plant.mass..g, y=NPP, color=Treatment)) +
  geom_line(aes(fill=Treatment, linetype=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) + 
  coord_cartesian(ylim=c(-20, 50)) +
  geom_hline(yintercept=0, linetype="longdash", color = "gray") +
  ylab(expression(paste("Net Production (", Delta, "O"[2],"%)"))) +
  theme(legend.position = "right") +
  Fig.formatting

# treatment effect (p=0.007)
# smoother significant for burned (p=0.002) but not unburned (p=0.326)


####### Time 3

m1.NPP.T3<-gam(NPP ~ Treatment + s(plant.mass..g, by= Treatment), subset = Time.point=="T3", data = O2.tanks, method = "REML")

m2.NPP.T3<-gam(NPP ~ Treatment + s(plant.mass..g), subset = Time.point=="T3", data = O2.tanks, method = "REML")

m3.NPP.T3<-gam(NPP ~ s(plant.mass..g), subset = Time.point=="T3", data = O2.tanks, method = "REML")

T3.NPP.AIC<-AIC(m1.NPP.T3, m2.NPP.T3, m3.NPP.T3)
# model with plot smooth by factor not different from reduced model, go with smooth by factor


summary(m2.NPP.T3)
anova.gam(m2.NPP.T3)
gam.check(m2.NPP.T3, rep=1000)
draw(m2.NPP.T3)
concrvity(m2.NPP.T3)
par(mfrow = c(2, 2))
plot(m2.NPP.T3, all.terms = TRUE, page=1)

# model predictions
NPP.diff.T3<-plot_difference(
  m2.NPP.T3,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

#plot for the model output on rawdata
NPP.T3.mod.plot<-
  plot_smooths(
  model = m2.NPP.T3,
  series = plant.mass..g,
  comparison = Treatment
) + 
  geom_point(data=T3.O2, aes(x=plant.mass..g, y=NPP, color=Treatment)) +
  geom_line(aes(fill=Treatment, linetype=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) + 
  coord_cartesian(ylim=c(-20, 50)) +
  geom_hline(yintercept=0, linetype="longdash", color = "gray") +
  ylab(expression(paste("Net Production (", Delta, "O"[2],"%)"))) +
  theme(legend.position = "right") +
  Fig.formatting

# treatment effect (p=0.009)
# smoother significant for burned (p<0.001) but not unburned (p=0.053)


####### Time 4

m1.NPP.T4<-gam(NPP ~ Treatment + s(plant.mass..g, by= Treatment), subset = Time.point=="T4", data = O2.tanks, method = "REML")

m2.NPP.T4<-gam(NPP ~ Treatment + s(plant.mass..g), subset = Time.point=="T4", data = O2.tanks, method = "REML")

m3.NPP.T4<-gam(NPP ~ s(plant.mass..g), subset = Time.point=="T4", data = O2.tanks, method = "REML")

T4.NPP.AIC<-AIC(m1.NPP.T4, m2.NPP.T4, m3.NPP.T4)
# model with plot smooth by factor not different from reduced model, go with smooth by factor


summary(m1.NPP.T4)
anova.gam(m1.NPP.T4)
gam.check(m1.NPP.T4, rep=1000)
draw(m1.NPP.T4)
concrvity(m1.NPP.T4)
par(mfrow = c(2, 2))
plot(m1.NPP.T4, all.terms = TRUE, page=1)

# model predictions
NPP.diff.T4<-plot_difference(
  m1.NPP.T4,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

#plot for the model output on rawdata
NPP.T4.mod.plot<-
  plot_smooths(
  model = m1.NPP.T4,
  series = plant.mass..g,
  comparison = Treatment
) + 
  geom_point(data=T4.O2, aes(x=plant.mass..g, y=NPP, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) + 
  coord_cartesian(ylim=c(-20, 50)) +
  geom_hline(yintercept=0, linetype="longdash", color = "gray") +
  ylab(expression(paste("Net Production (", Delta, "O"[2],"%)"))) +
  theme(legend.position = "right") +
  Fig.formatting

# no treatment effect (p=0.118)
# smoother significant for burned (p=0.020) but not unburned (p=0.327)

mod.RNPP<-rep(c("~Treatment + s(plant.mass..g, by= Treatment)", 
              "~Treatment + s(plant.mass..g)", 
              "~s(plant.mass..g)"), times=4)

mod.RNPP.df<- data.frame(mod.RNPP)

AIC.NPP<-bind_rows(T1.NPP.AIC, T2.NPP.AIC, T3.NPP.AIC, T4.NPP.AIC)
AIC.NPP.mod<-cbind(mod.RNPP.df, AIC.NPP)
write.csv(AIC.NPP.mod, "output/AIC models/AIC.NPP.mod.csv")

Table: Results for Time-1 NPP

anova.gam(m1.NPP.T1)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## NPP ~ Treatment + s(plant.mass..g, by = Treatment)
## 
## Parametric Terms:
##           df     F p-value
## Treatment  1 2.756    0.11
## 
## Approximate significance of smooth terms:
##                                      edf Ref.df     F p-value
## s(plant.mass..g):Treatmentburned   2.478  3.046 13.44 2.3e-05
## s(plant.mass..g):Treatmentunburned 1.690  2.090  6.36 0.00585

Table: Results for Time-2 NPP

anova.gam(m1.NPP.T2)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## NPP ~ Treatment + s(plant.mass..g, by = Treatment)
## 
## Parametric Terms:
##           df     F p-value
## Treatment  1 8.479 0.00745
## 
## Approximate significance of smooth terms:
##                                      edf Ref.df     F p-value
## s(plant.mass..g):Treatmentburned   1.967  2.431 7.392 0.00227
## s(plant.mass..g):Treatmentunburned 1.000  1.000 1.002 0.32638

Table: Results for Time-3 NPP

anova.gam(m1.NPP.T3)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## NPP ~ Treatment + s(plant.mass..g, by = Treatment)
## 
## Parametric Terms:
##           df     F p-value
## Treatment  1 8.118 0.00948
## 
## Approximate significance of smooth terms:
##                                      edf Ref.df     F  p-value
## s(plant.mass..g):Treatmentburned   3.414  4.166 8.236 0.000334
## s(plant.mass..g):Treatmentunburned 3.124  3.821 2.940 0.053008

Table: Results for Time-4 NPP

anova.gam(m1.NPP.T4)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## NPP ~ Treatment + s(plant.mass..g, by = Treatment)
## 
## Parametric Terms:
##           df    F p-value
## Treatment  1 2.62   0.118
## 
## Approximate significance of smooth terms:
##                                      edf Ref.df     F p-value
## s(plant.mass..g):Treatmentburned   2.757  3.382 3.717  0.0203
## s(plant.mass..g):Treatmentunburned 1.000  1.000 1.002  0.3268

Now, we will go through Respiration models and individual plots.

####### Time 1
m1.R.T1<-gam(R ~ Treatment + s(plant.mass..g, by= Treatment), subset = Time.point=="T1", data = O2.tanks, method = "REML")

m2.R.T1<-gam(R ~ Treatment + s(plant.mass..g), subset = Time.point=="T1", data = O2.tanks, method = "REML")

m3.R.T1<-gam(R ~ s(plant.mass..g), subset = Time.point=="T1", data = O2.tanks, method = "REML")

T1.R.AIC<-AIC(m1.R.T1, m2.R.T1, m3.R.T1)
# model with global best


summary(m3.R.T1)
anova.gam(m3.R.T1)
gam.check(m3.R.T1, rep=1000)
draw(m3.R.T1)
concrvity(m3.R.T1)
par(mfrow = c(2, 2))
plot(m3.R.T1, all.terms = TRUE, page=1)

# model predictions
R.diff.T1<-plot_difference(
  m1.R.T1,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
#plot for the model output on rawdata
R.T1.mod.plot<-
  plot_smooths(
  model = m3.R.T1,
  series = plant.mass..g,
) + 
  geom_point(data=T1.O2, aes(x=plant.mass..g, y=R, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) + 
  coord_cartesian(ylim=c(-40, 10)) +
  geom_hline(yintercept=0, linetype="longdash", color = "gray") +
  ylab(expression(paste("Net Respiration (", Delta, "O"[2],"%)"))) +
  theme(legend.position = "right") +
  Fig.formatting

# no treatment effect (p=0.229), smoothers significant (p<0.001)

####### Time 2

m1.R.T2<-gam(R ~ Treatment + s(plant.mass..g, by= Treatment), subset = Time.point=="T2", data = O2.tanks, method = "REML")

m2.R.T2<-gam(R ~ Treatment + s(plant.mass..g), subset = Time.point=="T2", data = O2.tanks, method = "REML")

m3.R.T2<-gam(R ~ s(plant.mass..g), subset = Time.point=="T2", data = O2.tanks, method = "REML")

T2.R.AIC<-AIC(m1.R.T2, m2.R.T2, m3.R.T2)
# model with global + treatment best

summary(m2.R.T2)
anova.gam(m2.R.T2)
gam.check(m2.R.T2, rep=1000)
draw(m2.R.T2)
concrvity(m2.R.T2)
par(mfrow = c(2, 2))
plot(m2.R.T2, all.terms = TRUE, page=1)

# model predictions
R.diff.T2<-plot_difference(
  m2.R.T2,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
#plot for the model output on rawdata
R.T2.mod.plot<-
  plot_smooths(
  model = m2.R.T2,
  series = plant.mass..g, 
  comparison= Treatment,
) + 
  geom_point(data=T2.O2, aes(x=plant.mass..g, y=R, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) + 
  geom_line(aes(fill=Treatment, linetype=Treatment)) +
  coord_cartesian(ylim=c(-40, 10)) +
  geom_hline(yintercept=0, linetype="longdash", color = "gray") +
  ylab(expression(paste("Net Respiration (", Delta, "O"[2],"%)"))) +
  theme(legend.position = "right") +
  Fig.formatting

# slight treatment effect (p=0.085)
# smoother significant for both burned and unburned (p<0.008)


####### Time 3
m1.R.T3<-gam(R ~ Treatment + s(plant.mass..g, by= Treatment), subset = Time.point=="T3", data = O2.tanks, method = "REML")

m2.R.T3<-gam(R ~ Treatment + s(plant.mass..g), subset = Time.point=="T3", data = O2.tanks, method = "REML")

m3.R.T3<-gam(R ~ s(plant.mass..g), subset = Time.point=="T3", data = O2.tanks, method = "REML")

T3.R.AIC<-AIC(m1.R.T3, m2.R.T3, m3.R.T3)
# model smmoth by factor best


summary(m1.R.T3)
anova.gam(m1.R.T3)
gam.check(m1.R.T3, rep=1000)
draw(m1.R.T3)
concrvity(m1.R.T3)
par(mfrow = c(2, 2))
plot(m1.R.T3, all.terms = TRUE, page=1)

# model predictions
R.diff.T3<-plot_difference(
  m1.R.T3,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
#plot for the model output on rawdata
R.T3.mod.plot<-
  plot_smooths(
  model = m1.R.T3,
  series = plant.mass..g,
  comparison = Treatment
) + 
  geom_point(data=T3.O2, aes(x=plant.mass..g, y=R, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) + 
  coord_cartesian(ylim=c(-40, 10)) +
  geom_hline(yintercept=0, linetype="longdash", color = "gray") +
  ylab(expression(paste("Net Respiration (", Delta, "O"[2],"%)"))) +
  theme(legend.position = "right") +
  Fig.formatting

# treatment effect (p=0.027)
# smoother significant for burned and unnburned (p<0.001)


####### Time 4

m1.R.T4<-gam(R ~ Treatment + s(plant.mass..g, by= Treatment), subset = Time.point=="T4", data = O2.tanks, method = "REML")

m2.R.T4<-gam(R ~ Treatment + s(plant.mass..g), subset = Time.point=="T4", data = O2.tanks, method = "REML")

m3.R.T4<-gam(R ~ s(plant.mass..g), subset = Time.point=="T4", data = O2.tanks, method = "REML")

T4.R.AIC<-AIC(m1.R.T4, m2.R.T4, m3.R.T4)
# model with global + treatment best


summary(m1.R.T4)
anova.gam(m1.R.T4)
gam.check(m1.R.T4, rep=1000)
draw(m1.R.T4)
concrvity(m1.R.T4)
par(mfrow = c(2, 2))
plot(m1.R.T4, all.terms = TRUE, page=1)

# model predictions
R.diff.T4<-plot_difference(
  m1.R.T4,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
#plot for the model output on rawdata
R.T4.mod.plot<-
  plot_smooths(
  model = m1.R.T4,
  series = plant.mass..g,
  comparison = Treatment
) + 
  geom_point(data=T4.O2, aes(x=plant.mass..g, y=R, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) + 
  coord_cartesian(ylim=c(-40, 10)) +
  geom_hline(yintercept=0, linetype="longdash", color = "gray") +
  ylab(expression(paste("Net Respiration (", Delta, "O"[2],"%)"))) +
  theme(legend.position = "right") +
  Fig.formatting

# no treatment effect (p=0.078)
# smoother significant for burned (p=0.004) but not unburned (p=0.965)


R.mod.plot<-plot_grid(
  R.T1.mod.plot+ theme(legend.position = "none")+ ggtitle("Day-10"),
  R.T2.mod.plot+ theme(legend.position = "none")+ ggtitle("Day-31"),
  R.T3.mod.plot+ theme(legend.position = "none")+ ggtitle("Day-59"),
  R.T4.mod.plot+ theme(legend.position = "none")+ ggtitle("Day-89"), extract.legend,
  rel_widths = c(8,8,8,8,3), ncol=5)

#ggsave("figures/R.mod.plot.long.pdf", height=6, width=12)

#### model differences
R.mod.diffs<-plot_grid(
  R.diff.T1+ theme(legend.position = "none")+ ggtitle("R-Day-10"),
  R.diff.T2+ theme(legend.position = "none")+ ggtitle("Day-31"),
  R.diff.T3+ theme(legend.position = "none")+ ggtitle("Day-59"),
  R.diff.T4+ theme(legend.position = "none")+ ggtitle("Day-89"),
  rel_widths = c(8,8,8,8), ncol=4)

#ggsave("figures/R.mod.diffs.pdf", height=3, width=10)

AIC.R<-bind_rows(T1.R.AIC, T2.R.AIC, T3.R.AIC, T4.R.AIC)
AIC.R.mod<-cbind(mod.RNPP.df, AIC.R)

write.csv(AIC.R.mod, "output/AIC models/AIC.R.mod.csv")

Table: Results for Time-1 Resp

anova.gam(m3.R.T1)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## R ~ s(plant.mass..g)
## 
## Approximate significance of smooth terms:
##                    edf Ref.df    F  p-value
## s(plant.mass..g) 2.520  3.097 12.8 2.32e-05

Table: Results for Time-2 Resp

anova.gam(m2.R.T2)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## R ~ Treatment + s(plant.mass..g)
## 
## Parametric Terms:
##           df     F p-value
## Treatment  1 6.443  0.0186
## 
## Approximate significance of smooth terms:
##                    edf Ref.df  F  p-value
## s(plant.mass..g) 5.710  6.758 10 1.52e-05

Table: Results for Time-3 Resp

anova.gam(m1.R.T3)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## R ~ Treatment + s(plant.mass..g, by = Treatment)
## 
## Parametric Terms:
##           df     F p-value
## Treatment  1 5.669  0.0268
## 
## Approximate significance of smooth terms:
##                                      edf Ref.df      F  p-value
## s(plant.mass..g):Treatmentburned   3.762  4.576 13.144 1.02e-05
## s(plant.mass..g):Treatmentunburned 3.274  4.000  7.775 0.000523

Table: Results for Time-4 Resp

anova.gam(m1.R.T4)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## R ~ Treatment + s(plant.mass..g, by = Treatment)
## 
## Parametric Terms:
##           df    F p-value
## Treatment  1 3.38  0.0784
## 
## Approximate significance of smooth terms:
##                                      edf Ref.df     F p-value
## s(plant.mass..g):Treatmentburned   2.927  3.587 5.293 0.00408
## s(plant.mass..g):Treatmentunburned 1.000  1.000 0.002 0.96531

Compile the NPP-R plots with model fits.

NPP.R.alltimes.long<-plot_grid(
  NPP.T1.mod.plot+ theme(legend.position = "none"),
  NPP.T2.mod.plot+ theme(legend.position = "none"),
  NPP.T3.mod.plot+ theme(legend.position = "none"),
  NPP.T4.mod.plot+ theme(legend.position = "none"), extract.legend,
  R.T1.mod.plot+ theme(legend.position = "none"),
  R.T2.mod.plot+ theme(legend.position = "none"),
  R.T3.mod.plot+ theme(legend.position = "none"),
  R.T4.mod.plot+ theme(legend.position = "none"), extract.legend,
  rel_widths = c(8,8,8,8,3, 8,8,8,8,3), ncol=5, 
      labels=c('A','', '', '', '', 
               'B', '', '', '', ''), label_size=8)
ggsave("figures/NPP.R.alltimes.long.pdf", height=7, width=12)

NPP.R.alltimes.long
**Figure** (**A**) Net ecosystem productivity (NPP) and (**B**) respiration (R) in treatments receiving burned and unburned plant material across four sampling periods. Black lines with gray confidence intervals indicate global smoothers across all data points; solid (burned) and dotted (unburned) black lines together represent treatment-level intercepts with global smoothers; colored lines indicate factor-smooths that vary between treatments.

Figure (A) Net ecosystem productivity (NPP) and (B) respiration (R) in treatments receiving burned and unburned plant material across four sampling periods. Black lines with gray confidence intervals indicate global smoothers across all data points; solid (burned) and dotted (unburned) black lines together represent treatment-level intercepts with global smoothers; colored lines indicate factor-smooths that vary between treatments.

Model differences between the two factor-smoothers. The areas in pink show where there are significant differences between the two smoothers, indicating treatment effects.

NPP.R.mod.diffs<-plot_grid(
  NPP.diff.T1+ theme(legend.position = "none"),
  NPP.diff.T2+ theme(legend.position = "none"),
  NPP.diff.T3+ theme(legend.position = "none"),
  NPP.diff.T4+ theme(legend.position = "none"),
  R.diff.T1+ theme(legend.position = "none"),
  R.diff.T2+ theme(legend.position = "none"),
  R.diff.T3+ theme(legend.position = "none"),
  R.diff.T4+ theme(legend.position = "none"),
  rel_widths = c(8,8,8,8,8,8,8,8), ncol=4)
ggsave("figures/NPP.R.mod.diffs.alt.pdf", height=7, width=12)

NPP.R.mod.diffs

Isotopes

Isotopes and C:N (carbon to nitrogen molar concentrations) for starting materials used in the experiment and plankton fractions sampled at time 1 (Day-10) and time 2 (Day-31).


#########  Time 1 and Time 2
topes<-read.csv("data/Isotopes/Pyro_isotopes.csv")
topes$C.N <-(topes$Total.C..ug/12)/(topes$Total.N..ug/14) # C mol : N mol

cols<-c("Time.point", "Treatment", "Type", "Tank") # columns to make factors
topes[cols] <- lapply(topes[cols], factor) # make all these factors

##### make data frames
# treatment data df
topes.trt<-topes[(topes$Treatment=="burned" | topes$Treatment=="unburned"),]
topes.trt<-droplevels(topes.trt)
topes.trt$Type<-factor(topes.trt$Type, 
                         levels=c("plankton", "POM"))

# control and start plant materials df
topes.controls<-topes[!(topes$Treatment=="burned" | topes$Treatment=="unburned"),]

Starting materials

We will turn our attention to the starting materials, the burned and unburned 15N-labeled sage and non-labeled-willow (and non-labeled stock plankton) from the beginning of the experiment to see what their C:N values and isotope values are. We define these as “control” samples and include the tin blanks, plankton, and starting materials.

  • The code chunk below structures contrasts and runs non-parametric tests and linear models testing for differences between sample types.
  • Make a combined figure of nitrogen isotope values and C:N values
########## ########## ########## 
# run some stats to see how the control material differs from each other

# make a burning treatment
topes.controls$Burn.Trt=as.factor(word(topes.controls$Type, -1, sep="[.]"))

# make a plant name
topes.controls$Plant=as.factor(word(topes.controls$Type, 1, sep="[.]"))

### test some models on controls
# remove blanks and plankton, keeping only plants
topes.controls.plants<-topes.controls[!(topes.controls$Plant=="blank" |
                                          topes.controls$Plant=="plankton" ),]
topes.controls.plants$Plant<-droplevels(topes.controls.plants$Plant)

# keep only non-enriched samples (remove sage)
topes.controls.non.enrich<-topes.controls[!(topes.controls$Plant=="blank" |
                                          topes.controls$Plant=="sage" ),]
topes.controls.non.enrich$Plant<-droplevels(topes.controls.non.enrich$Plant)


######## test plant species differences
mwu(topes.controls.plants, d15N, Plant)
# d15N sage and willow differ (p<0.001)
mwu(topes.controls.plants, C.N, Plant) 
# C.N sage and willow differ (p=0.013)

par(mfrow=c(1,2))
boxplot(d15N~Plant, data=topes.controls.plants)
boxplot(C.N~Plant, data=topes.controls.plants)


######## test difference between willow and plankton 
mwu(topes.controls.non.enrich, d15N, Plant)
 # d15N plankton and willow differ (p<0.001)
mwu(topes.controls.non.enrich, C.N, Plant) # C:N plankton and willow differ (p<0.001)
par(mfrow=c(1,2))
boxplot(d15N~Plant, data=topes.controls.non.enrich)
boxplot(C.N~Plant, data=topes.controls.non.enrich)


############# separate plant dfs
#### Sage d15N
topes.controls.sage<-topes.controls[(topes.controls$Plant=="sage"),]
topes.controls.sage$Plant<-droplevels(topes.controls.sage$Plant)
topes.controls.sage$Burn.Trt<-droplevels(topes.controls.sage$Burn.Trt)

# how do different types of sage compare across burn/unburn
# first, no difference between burned or very burned sage
anova(lm(d15N~Burn.Trt, data=topes.controls.sage[!(topes.controls.sage$Burn.Trt=="unburned"),]))

# convert to just 2 levels, no difference here either
topes.controls.sage$Burn.Unb<-ifelse(topes.controls.sage$Burn.Trt=="burned", "burned",
                                     ifelse(topes.controls.sage$Burn.Trt=="very burned", "burned",
                                     "unburned"))


mod.sage<-lm(d15N~Burn.Trt, data=topes.controls.sage) # keep at 3 levels
anova(mod.sage) 
# no difference in d15N for burned, unburned, very burned sage (p=0.423)

#### Sage C.N
mod.sage.CN<-lm(C.N~Burn.Trt, data=topes.controls.sage)
anova(mod.sage.CN) 
posthoc<-emmeans(mod.sage.CN, ~Burn.Trt)
multcomp::cld(posthoc, Letters=letters)
# Sage: difference in unburned, burned, very burned for C:N

par(mfrow=c(1,2))
boxplot(d15N~Burn.Trt, data=topes.controls.sage)
boxplot(C.N~Burn.Trt, data=topes.controls.sage)



###########################
#### Willow d15N
topes.controls.will<-topes.controls[(topes.controls$Plant=="willow"),]
topes.controls.will$Plant<-droplevels(topes.controls.will$Plant)
topes.controls.will$Burn.Trt<-droplevels(topes.controls.will$Burn.Trt)

mod<-lm(C.N~Burn.Trt, data=topes.controls.will)
anova(mod) 
# no difference in burned/unburned willow d15N

#### Willow C.N
mod<-lm(C.N~Burn.Trt, data=topes.controls.will)
anova(mod) 
# Willow: no difference in unburned, burned C:N (p=0.061)

par(mfrow=c(1,2))
boxplot(d15N~Burn.Trt, data=topes.controls.will)
boxplot(C.N~Burn.Trt, data=topes.controls.will)


######### make summary dfs
# summarize by plants
d15N.plant<-aggregate(d15N~Plant, topes.controls, FUN=mean)
d15N.plantSD<-aggregate(d15N~Plant, topes.controls, FUN=sd)
d15N.plant[3]<-d15N.plantSD[2]
colnames(d15N.plant)<-c("Plant", "d15N", "SD")

CN.plant<-aggregate(C.N~Plant, topes.controls, FUN=mean)
CN.plantSD<-aggregate(C.N~Plant, topes.controls, FUN=sd)
CN.plant[3]<-CN.plantSD[2]
colnames(CN.plant)<-c("Plant", "C.N", "SD")

# summary df d15N
d15N.cont<-aggregate(d15N~Type, topes.controls, FUN=mean)
d15N.cont.n<-aggregate(d15N~Type, topes.controls, FUN=length)
d15N.cont.SD<-aggregate(d15N~Type, topes.controls, FUN=sd)
d15N.cont[3]<- d15N.cont.SD[2]
d15N.cont[4]<- d15N.cont.n[2]
colnames(d15N.cont)<-c("Type", "d15N", "SD", "n")

# summary df control C:N
CN.cont<-aggregate(C.N~Type, topes.controls, FUN=mean)
CN.cont.n<-aggregate(C.N~Type, topes.controls, FUN=length)
CN.cont.SD<-aggregate(C.N~Type, topes.controls, FUN=sd)
CN.cont[3]<- CN.cont.SD[2]
CN.cont[4]<- CN.cont.n[2]
colnames(CN.cont)<-c("Type", "C.N", "SD", "n")
# make boxplots of control sample d15N and C:N
########## control plots
# set levels
topes.controls$Type<-factor(topes.controls$Type, 
                         levels=c("blank", "plankton.stock", 
                                  "willow.unburned", "willow.burned",
                                  "sage.unburned", "sage.burned", 
                                  "sage.veryburned", "sage.stem.burned"))

#### controls d15N boxplot
iso.plot.control.d15N<-ggplot(data=topes.controls,  aes(x=Type, y=d15N, fill=Type)) +
  geom_boxplot() +
  geom_point(pch = 21, position = position_jitterdodge(), alpha=0.6)+
  ylab(expression(paste(delta^{15}, N, " (\u2030, air)"))) +
  scale_fill_manual(values = c("azure2", "cornflowerblue",
                                "darkgoldenrod1", "indianred2",
                                "aquamarine3", "antiquewhite3",
                                "darkolivegreen4", "lightsalmon")) +
  xlab("control types") +  Fig.formatting +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) 


###### control C:N
topes.controls.CN<-topes.controls %>% drop_na(C.N) # drop the NAs for C.N, makes plotting problematic

iso.plot.control.CN<-ggplot(data=topes.controls.CN,  aes(x=Type, y=C.N, fill=Type)) +
  geom_boxplot() +
  geom_point(pch = 21, position = position_jitterdodge(), alpha=0.6)+
  ylab("C:N") +
  scale_fill_manual(values = c("cornflowerblue",
                                "darkgoldenrod1", "indianred2",
                                "aquamarine3", "antiquewhite3",
                                "darkolivegreen4", "lightsalmon")) +
  xlab("control types") +  Fig.formatting +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))


####### combine plots
# legend
extract.legend.cont <- get_legend(
  # create some space to the left of the legend
  iso.plot.control.d15N + theme(legend.box.margin = margin(0, 0, 0, 10)))


## combine 
control.iso.alltime<- 
  plot_grid(iso.plot.control.d15N + theme(legend.position = "none"),
            iso.plot.control.CN + theme(legend.position = "none"),
            extract.legend.cont, rel_widths = c(8,8,3), ncol=3, labels=c('A', 'B'), label_size=8)

control.iso.alltime
**Figure** (**A**) Nitrogen isotope values and (**B**) C:N ratio for experimental controls (tin blanks), stock plankton, and burned or unburned plant material (willow, sage).

Figure (A) Nitrogen isotope values and (B) C:N ratio for experimental controls (tin blanks), stock plankton, and burned or unburned plant material (willow, sage).

ggsave("figures/iso.controls.pdf", encod="MacRoman", height=5, width=10)

Plankton C:N

We will test C:N vs. plant material models and generate plot, fit with GAMs * Here we will test if the C:N was consistent across time, or what factors may influence C:N. This is important to verify assumptions. * We are using 15N transfer between trophic levels, assuming our measurements of efficiency in nitrogen transfer reflect carbon and energy transfer between trophic levels.

We will run through the model fitting and test for differences in the Treatments (Burned and Unburned plant material), Plankton Type (either > or < 63 μm), and Timepoint (Time 1 or Time 2).

############# all plankton T1 and T2
m1.CN <- gam(C.N ~ Treatment + Type + Time.point +
            s(plant.mass..g, by=Treatment),
            data=topes.trt, method="REML", family="gaussian")

m2.CN <- gam(C.N ~ Treatment + Type + Time.point +
            s(plant.mass..g), 
            data=topes.trt, method="REML", family="gaussian")

m3.CN <- gam(C.N ~
            s(plant.mass..g), 
            data=topes.trt, method="REML", family="gaussian")

m4.CN <- gam(C.N ~ Treatment + Type +
            s(plant.mass..g, by=Time.point),
            data=topes.trt, method="REML", family="gaussian")

m5.CN <- gam(C.N ~ Treatment + Type +
            s(plant.mass..g, by=Treatment),
            data=topes.trt, method="REML", family="gaussian")

#best model here
m6.CN <- gam(C.N ~ Type +
            s(plant.mass..g, by=Treatment),
            data=topes.trt, method="REML", family="gaussian")

m7.CN <- gam(C.N ~ Treatment +
            s(plant.mass..g, by=Type),
            data=topes.trt, method="REML", family="gaussian")

m8.CN <- gam(C.N ~ Type +
            s(plant.mass..g, by=Type),
            data=topes.trt, method="REML", family="gaussian")


AIC.CN<-AIC(m1.CN, m2.CN, m3.CN, m4.CN, m5.CN, m6.CN, m7.CN, m8.CN)
## additive model best fit, but no treatment or type effect

summary(m6.CN)
anova.gam(m6.CN)
gam.check(m6.CN, rep=1000)
draw(m6.CN)
concrvity(m6.CN)
par(mfrow = c(1, 2))
plot(m6.CN, all.terms = TRUE, page=1)

# model for smoothing
msmooth.CN<-gam(C.N ~ Type +
            s(plant.mass..g, by=Type),
            data=topes.trt, method="REML", family="gaussian")

# model predictions
CN.diff<-plot_difference(
  m1.CN,
  series = plant.mass..g,
  difference = list(Type = c("plankton", "POM"))
)

#####

# linear model approach
CN.all.mod<-lm(C.N~ Treatment+Type+Time.point, data=topes.trt, na.action=na.exclude) 
print(Anova(CN.all.mod, type=2), digits=5)
posthoc<-emmeans(CN.all.mod, ~Type)
multcomp::cld(posthoc, Letters=letters)

##### plot for the model output on rawdata
CN.mod.plot.timepooled<-
  plot_smooths(
  model = msmooth.CN,
  series = plant.mass..g,
  comparison = Type)  + 
  theme(legend.position = "none") +
  geom_point(data=topes.trt, 
             aes(x=plant.mass..g, y=C.N, color=Type, fill=Type)) +
  scale_fill_manual(values = c("deepskyblue4", "darkseagreen"), guide='none') +
  scale_color_manual(name="Plankton", values = c("deepskyblue4", "darkseagreen"), 
                     labels = c(expression(paste("> 63"~mu,"m")), 
                                expression(paste("< 63"~mu,"m")))) +
  theme(legend.position = "right") +
  ggtitle("Days 10 and 31") + 
  coord_cartesian(ylim=c(0, 20)) +
  ylab("C:N") +
  xlab("plant material (g)") +
  Fig.formatting 

ggsave("figures/CN.mod.plot.timepooled.pdf", height=4, width=5, encod="MacRoman")


############
### All time C.N boxplot
CNbox.all.time<-ggplot(topes.trt, aes(x=Treatment, y=C.N, fill=Type)) + 
  geom_boxplot() +
  geom_point(pch = 21, position = position_jitterdodge(), alpha=0.6) +
  scale_fill_manual(name="Plankton", values = c("deepskyblue4", "darkseagreen"), 
                     labels = c(expression(paste("> 63"~mu,"m")), 
                                expression(paste("< 63"~mu,"m")))) +
  coord_cartesian(ylim=c(0, 20)) +
  ylab("C:N") +
  Fig.formatting

ggsave("figures/CNbox.all.time.pdf", height=4, width=5, encod="MacRoman")


C.Nboxplots<- plot_grid(CN.mod.plot.timepooled, 
                    CNbox.all.time,
                    rel_widths = c(8,8), ncol=2, labels=c('A', 'B'), label_size=8)
C.Nboxplots
**Figure** (**A**) Plankton C:N along the plant material gradient pooled across days (10 and 31) and treatments (burned and unburned), and (**B**) plankton C:N in treatment tanks receiving burned and unburned plant material.

Figure (A) Plankton C:N along the plant material gradient pooled across days (10 and 31) and treatments (burned and unburned), and (B) plankton C:N in treatment tanks receiving burned and unburned plant material.

Table: Results for C:N across size fractions pooled at Day-10 and 31.

anova.gam(m6.CN)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## C.N ~ Type + s(plant.mass..g, by = Treatment)
## 
## Parametric Terms:
##      df     F  p-value
## Type  1 22.58 6.04e-06
## 
## Approximate significance of smooth terms:
##                                      edf Ref.df      F p-value
## s(plant.mass..g):Treatmentburned   4.426  5.346 12.421 < 2e-16
## s(plant.mass..g):Treatmentunburned 1.650  2.039  6.618 0.00182

Table: Results for C:N across burned/unburned samples and size fractions pooled at Day-10 and 31.

print(Anova(CN.all.mod, type=2), digits=5)
## Anova Table (Type II tests)
## 
## Response: C.N
##            Sum Sq  Df F value    Pr(>F)    
## Treatment    0.08   1  0.0116 0.9145723    
## Type        98.50   1 13.7615 0.0003201 ***
## Time.point   0.55   1  0.0765 0.7825313    
## Residuals  830.26 116                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Trophic Transfer Efficiency

We will not use a two-member mixing model to calculate %sage-^15^N in the plankton. The %sage-15N is a proxy for trophic transfer efficiency, using the transfer of N from inorganic forms into phytoplankton and the incorporation of this N into higher trophic levels (zooplankton consumers). Here, the higher the enrichment of 15N in the plankton, the more the source of N reflects terrestrial material (i.e., 15N-labeled sage) and the more allochthonous nutrition is supplying N for plankton consumers.

  • Overall: Higher %sage-15N in plankton = more allochthonous/terrestrial subsidies N into plankton
  • Autochthonous end-member: we used the value of 11 per mil, which reflects the start values of plankton/POM/willow.
  • Terrestrial subsidy end-memembr: we used δ15N value of sage (no differed in burned vs. unburned) of 296 permil.
  • we recognize that the absolute contribution of terrestrial subsidies to plankton would be higher, since tanks received both sage and willow, but willow was not labeled.

Format and run the mixing model for % sage.

# mixing model
head(topes.trt)
topes.trt<-droplevels(topes.trt)


### values for controls
d15N.cont # summary mean d15N by all controls
d15N.plant # summary by plants, # stock plantkon 11, # sage 296, #  willow 13

# summary mean atom percent enrichment
F.cont<-aggregate(at.P..15N  ~ Type, topes.controls, mean)
F.plant<-aggregate(at.P..15N~Plant, topes.controls, FUN=mean)
# sage ~0.475
# willow 0.371

# 2 source mixing model (Post 2002), used d15N values here

# alpha = percent Sage from food web 1
# %Sage = (d15N sample - d15N base 2 [i.e., no-label food])/ (d15N sage food 1 - source 2)
#  d15N values of base 2 = 11 permil for algae/plankton stock/willow
#  d15N value of base 1 = 298 permil for sage

# framed differently from Robinson 2001, TREE
# xtracer = frction of tracer
# Xtracer = (d15N-sample - d15N background) / (d15N-tracer - d15N-background)

topes.trt$percent.sage<-(topes.trt$d15N-12)/(296-12)*100

# unicode text for micrometer = \u03BC, use this in legend


############# all plankton T1
m1.T1.sage <- gam(percent.sage ~ Treatment + Type +
            s(plant.mass..g, by=Treatment), 
            subset = Time.point=="T1", data=topes.trt, method="REML", family="gaussian")

m2.T1.sage <- gam(percent.sage ~ Treatment + Type +
            s(plant.mass..g), 
            subset = Time.point=="T1", data=topes.trt, method="REML", family="gaussian")

m3.T1.sage <- gam(percent.sage ~
                     s(plant.mass..g), 
            subset = Time.point=="T1", data=topes.trt, method="REML", family="gaussian")


AIC.sage.T1<-AIC(m1.T1.sage, m2.T1.sage, m3.T1.sage)
## additive model best fit

summary(m1.T1.sage)
anova.gam(m1.T1.sage)
gam.check(m1.T1.sage, rep=1000)
draw(m1.T1.sage)
concrvity(m1.T1.sage)
par(mfrow = c(1, 2))
plot(m1.T1.sage, all.terms = TRUE, page=1)

# model predictions
per.Sage.diff.T1<-plot_difference(
  m1.T1.sage,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
# model for smoothing
msmooth.T1.sage<- gam(percent.sage ~ Treatment +
            s(plant.mass..g, by=Treatment), 
            subset = Time.point=="T1", data=topes.trt, method="REML", family="gaussian")

#plot for the model output on rawdata
per.Sage.T1.mod.plot<-
  plot_smooths(
  model = msmooth.T1.sage,
  series = plant.mass..g,
  comparison = Treatment
)  + theme(legend.position = "none") +
  geom_point(data=topes.trt[(topes.trt$Time.point=="T1"),], 
             aes(x=plant.mass..g, y=percent.sage, color=Treatment, shape=Type)) +
  scale_shape_manual(name="Plankton", values = c(17, 16), 
                     labels = c(expression(paste("> 63"~mu,"m")), 
                                expression(paste("< 63"~mu,"m")))) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +
  ylab("% Sage")+
  xlab("plant material (g)") +
  ggtitle("Time-1") +
  coord_cartesian(ylim=c(0, 100)) +
  Fig.formatting +
  theme(legend.key.size = unit(1,"line"))

# overall an effect of burning with both smoothers being significant by treatment
# no effect of type, POM and plankton with similar d15N values


############# all plankton T2
m1.T2.sage <- gam(percent.sage ~ Treatment + Type +
            s(plant.mass..g, by=Treatment), 
            subset = Time.point=="T2", data=topes.trt, method="REML", family="gaussian")

m2.T2.sage <- gam(percent.sage ~ Treatment + Type +
            s(plant.mass..g), 
            subset = Time.point=="T2", data=topes.trt, method="REML", family="gaussian")

m3.T2.sage <- gam(percent.sage ~
                     s(plant.mass..g), 
            subset = Time.point=="T2", data=topes.trt, method="REML", family="gaussian")


AIC.sage.T2<-AIC(m1.T2.sage, m2.T2.sage, m3.T2.sage)
# m2.T2.sage preferred
# compare across

summary(m1.T2.sage)
anova.gam(m1.T2.sage)
gam.check(m1.T2.sage, rep=1000)
draw(m1.T2.sage)
concrvity(m1.T2.sage)
par(mfrow = c(1, 2))
plot(m1.T2.sage, all.terms = TRUE, page=1)

# model predictions
per.Sage.diff.T2<-plot_difference(
  m1.T2.sage,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
# model for smoothing
msmooth.T2.sage<- gam(percent.sage ~ Treatment +
            s(plant.mass..g, by=Treatment), 
            subset = Time.point=="T2", data=topes.trt, method="REML", family="gaussian")

#plot for the model output on rawdata
per.Sage.T2.mod.plot<-
  plot_smooths(
  model = msmooth.T2.sage,
  series = plant.mass..g,
  comparison = Treatment
)  + theme(legend.position = "none") +
  geom_point(data=topes.trt[(topes.trt$Time.point=="T2"),], 
             aes(x=plant.mass..g, y=percent.sage, color=Treatment, shape=Type)) +
  scale_shape_manual(name="Plankton", values = c(17, 16), 
                     labels = c(expression(paste("> 63"~mu,"m")), 
                                expression(paste("< 63"~mu,"m")))) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +
  ylab("% Sage")+
  xlab("plant material (g)") +
  ggtitle("Time-2") +
  coord_cartesian(ylim=c(0, 100)) +
  Fig.formatting +
  theme(legend.key.size = unit(1,"line"))

# effect of treatment (p<0.001) but not Type (p=0.321)
# smoother significant for both terms


### model plots for percent sage mixing model

## AIC table
mod.sag.top<-rep(c( "Treatment + Type + s(plant.mass..g, by=Treatment)", 
              "Treatment + Type + s(plant.mass..g)",
              "s(plant.mass..g)"), times=2)

mod.sag.df<- data.frame(mod.sag.top)
AIC.sag.topes<-bind_rows(AIC.sage.T1, AIC.sage.T2)

AIC.sag.mod<-cbind(mod.sag.df, AIC.sag.topes)
write.csv(AIC.sag.mod, "output/AIC models/AIC.sag.mod.csv")

Table: Results for %sage-15N across burned/unburned treatments at Day-10.

anova.gam(m1.T1.sage)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## percent.sage ~ Treatment + Type + s(plant.mass..g, by = Treatment)
## 
## Parametric Terms:
##           df      F  p-value
## Treatment  1 31.261 9.64e-07
## Type       1  1.721    0.196
## 
## Approximate significance of smooth terms:
##                                      edf Ref.df     F p-value
## s(plant.mass..g):Treatmentburned   3.560  4.338 136.8  <2e-16
## s(plant.mass..g):Treatmentunburned 3.921  4.762 173.6  <2e-16

Table: Results for %sage-15N across burned/unburned treatments at Day-31.

anova.gam(m1.T2.sage)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## percent.sage ~ Treatment + Type + s(plant.mass..g, by = Treatment)
## 
## Parametric Terms:
##           df      F  p-value
## Treatment  1 13.082 0.000704
## Type       1  1.004 0.321237
## 
## Approximate significance of smooth terms:
##                                      edf Ref.df      F p-value
## s(plant.mass..g):Treatmentburned   4.669  5.621  79.45  <2e-16
## s(plant.mass..g):Treatmentunburned 3.340  4.082 125.45  <2e-16

Generate the combined model plots for %-sage-15N.

# legend
extract.legend.mix <- get_legend(
  # create some space to the left of the legend
  per.Sage.T2.mod.plot + theme(legend.box.margin = margin(0, 0, 0, 10)))


## combine 
sage.mix.model<- plot_grid(per.Sage.T1.mod.plot + theme(legend.position = "none"), 
                    per.Sage.T2.mod.plot + theme(legend.position = "none"),
                    extract.legend.mix,
                    rel_widths = c(8,8,3), ncol=3, labels=c('A', 'B', ''), label_size=8)
sage.mix.model
**Figure** Trophic transfer as the % sage-derived 15N from a two-source mixing model as a metric for plant-based subsidies in treatments receiving burned and unburned plant material at Days-10 and 31.

Figure Trophic transfer as the % sage-derived 15N from a two-source mixing model as a metric for plant-based subsidies in treatments receiving burned and unburned plant material at Days-10 and 31.


ggsave("figures/Isotope.mixmodel.pdf", encod="MacRoman", height=4, width=8)

# and plot difference
sage.mix.model.diff<- plot_grid(per.Sage.diff.T1 + theme(legend.position = "none"), 
                    per.Sage.diff.T2 + theme(legend.position = "none"),
                    rel_widths = c(8,8), ncol=2)
sage.mix.model.diff
**Figure** Model effects from GAMs with differences between smoothers for % sage-derived 15N at Day-10 and Day-31 in tanks receiving burned and unburned plant material.

Figure Model effects from GAMs with differences between smoothers for % sage-derived 15N at Day-10 and Day-31 in tanks receiving burned and unburned plant material.

ggsave("figures/Isotope.mix.plotdiff.pdf", encod="MacRoman", height=4, width=8)

We also ran model fits and analysis on the raw isotope data for the plankton (δ15N) outside of the mixing model. See supplemental plots for output and code below.


## make d15N plots as well -- these follow the % sage, but are informative with the control plots to see the d15N of plankton and the 2 end members.

#### d15N isotope plots for treatments

############# all plankton T1
m1.T1.d15N <- gam(d15N ~ Treatment + Type +
            s(plant.mass..g, by=Treatment), 
            subset = Time.point=="T1", data=topes.trt, method="REML", family="gaussian")

m2.T1.d15N <- gam(d15N ~ Treatment + Type +
            s(plant.mass..g), 
            subset = Time.point=="T1", data=topes.trt, method="REML", family="gaussian")

m3.T1.d15N <- gam(d15N ~
            s(plant.mass..g), 
            subset = Time.point=="T1", data=topes.trt, method="REML", family="gaussian")

AIC.d15N.T1<-AIC(m1.T1.d15N, m2.T1.d15N, m3.T1.d15N)
## additive model best fit

summary(m1.T1.d15N)
anova.gam(m1.T1.d15N)
gam.check(m1.T1.d15N, rep=1000)
draw(m1.T1.d15N)
concrvity(m1.T1.d15N)
par(mfrow = c(1, 2))
plot(m1.T1.d15N, all.terms = TRUE, page=1)

# model predictions
d15N.diff.T1<-plot_difference(
  m1.T1.d15N,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
# model for smoothing
msmooth.T1.d15N<- gam(d15N ~ Treatment +
            s(plant.mass..g, by=Treatment), 
            subset = Time.point=="T1", data=topes.trt, method="REML", family="gaussian")

#plot for the model output on rawdata
d15N.T1.mod.plot<-
  plot_smooths(
  model = msmooth.T1.d15N,
  series = plant.mass..g,
  comparison = Treatment
)  + theme(legend.position = "none") +
  geom_point(data=topes.trt[(topes.trt$Time.point=="T1"),], 
             aes(x=plant.mass..g, y=d15N, color=Treatment, shape=Type)) +
  scale_shape_manual(name="Plankton", values = c(17, 16), 
                     labels = c(expression(paste("> 63"~mu,"m")), 
                                expression(paste("< 63"~mu,"m")))) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +
  ylab(expression(paste(delta^{15}, N, " (\u2030, air)"))) +
  xlab("plant material (g)") +
  ggtitle("Time-1") +
  coord_cartesian(ylim=c(0, 250)) +
  Fig.formatting +
  theme(legend.key.size = unit(1,"line"))

# overall an effect of burning with both smoothers being significant by treatment
# no effect of type, POM and plankton with similar d15N values


############# all plankton T2
m1.T2.d15N <- gam(d15N ~ Treatment + Type +
            s(plant.mass..g, by=Treatment), 
            subset = Time.point=="T2", data=topes.trt, method="REML", family="gaussian")

m2.T2.d15N <- gam(d15N ~ Treatment + Type +
            s(plant.mass..g), 
            subset = Time.point=="T2", data=topes.trt, method="REML", family="gaussian")

m3.T2.d15N <- gam(d15N ~
            s(plant.mass..g), 
            subset = Time.point=="T2", data=topes.trt, method="REML", family="gaussian")


AIC.d15N.T2<-AIC(m1.T2.d15N, m2.T2.d15N, m3.T2.d15N)
## additive model best fit

summary(m1.T2.d15N)
anova.gam(m1.T2.d15N)
gam.check(m1.T2.d15N, rep=1000)
draw(m1.T2.d15N)
concrvity(m1.T2.d15N)
par(mfrow = c(1, 2))
plot(m1.T2.d15N, all.terms = TRUE, page=1)

# model predictions
d15N.diff.T2<-plot_difference(
  m1.T2.d15N,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
# model for smoothing
msmooth.T2.d15N<- gam(d15N ~ Treatment +
            s(plant.mass..g, by=Treatment), 
            subset = Time.point=="T2", data=topes.trt, method="REML", family="gaussian")

#plot for the model output on rawdata
d15N.T2.mod.plot<-
  plot_smooths(
  model = msmooth.T2.d15N,
  series = plant.mass..g,
  comparison = Treatment
)  + theme(legend.position = "none") +
  geom_point(data=topes.trt[(topes.trt$Time.point=="T2"),], 
             aes(x=plant.mass..g, y=d15N, color=Treatment, shape=Type)) +
  scale_shape_manual(name="Plankton", values = c(17, 16), 
                     labels = c(expression(paste("> 63"~mu,"m")), 
                                expression(paste("< 63"~mu,"m")))) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +
  ylab(expression(paste(delta^{15}, N, " (\u2030, air)"))) +
  xlab("plant material (g)") +
  ggtitle("Time-2") +
  coord_cartesian(ylim=c(0, 250)) +
  Fig.formatting +
  theme(legend.key.size = unit(1,"line"))

d15N.model<- plot_grid(d15N.T1.mod.plot + theme(legend.position = "none"), 
                    d15N.T2.mod.plot + theme(legend.position = "none"),
                    extract.legend.mix, rel_widths = c(8,8,3), ncol=3)

ggsave("figures/d15N.model.pdf", encod="MacRoman", height=5, width=10)

################

mod.d15N<-rep(c("Treatment + Type + s(plant.mass..g, by=Treatment)", 
              "Treatment + Type + s(plant.mass..g)",
              "s(plant.mass..g)"), times=2)

mod.d15N.df<- data.frame(mod.d15N)
AIC.d15N<-bind_rows(AIC.d15N.T1, AIC.d15N.T2)

AIC.d15N.mod<-cbind(mod.d15N.df, AIC.d15N)
write.csv(AIC.d15N.mod, "output/AIC models/AIC.d15N.mod.csv")

Plant material

Plant material for the starting material (sage or willow, stems or sticks). This is useful in determining how fire impacted the nutrients in the plant material.
* First, run some stats to see what is happening and where differences lie.
* We will then make a summary boxplot figure

plant.nut<-read.csv("data/Pyro_plant material_elemental.csv")

fac<-c("Sample.Name", "type", "plant", "treatment", "rep") # make factors
plant.nut[fac]<-lapply(plant.nut[fac],factor)

sage.nut<-plant.nut[(plant.nut$plant=="sage"),]
will.nut<-plant.nut[(plant.nut$plant=="willow"),]

### Sage ### 
######### %N
plant.N.sag<-lm(N~treatment*type, data=sage.nut)
Anova(plant.N.sag, type=3) # 2 way interaction and main effects
## Anova Table (Type III tests)
## 
## Response: N
##                Sum Sq Df   F value    Pr(>F)    
## (Intercept)    7.0227  1 2171.5213 4.971e-11 ***
## treatment      0.0280  1    8.6632  0.018615 *  
## type           0.2604  1   80.5246 1.894e-05 ***
## treatment:type 0.0705  1   21.8099  0.001602 ** 
## Residuals      0.0259  8                        
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

posthoc<-emmeans(plant.N.sag, ~treatment| type)
multcomp::cld(posthoc, Letters=letters)
## type = leaf:
##  treatment emmean     SE df lower.CL upper.CL .group
##  burned     1.530 0.0328  8    1.454     1.61  a    
##  unburned   1.667 0.0328  8    1.591     1.74   b   
## 
## type = stem:
##  treatment emmean     SE df lower.CL upper.CL .group
##  unburned   0.943 0.0328  8    0.868     1.02  a    
##  burned     1.113 0.0328  8    1.038     1.19   b   
## 
## Confidence level used: 0.95 
## significance level used: alpha = 0.05 
## NOTE: If two or more means share the same grouping letter,
##       then we cannot show them to be different.
##       But we also did not show them to be the same.

########## %P 
plant.P.sag<-lm(P~treatment*type, data=sage.nut)
Anova(plant.P.sag, type=3) # just type
## Anova Table (Type III tests)
## 
## Response: P
##                  Sum Sq Df  F value    Pr(>F)    
## (Intercept)    0.314928  1 804.0715 2.586e-09 ***
## treatment      0.000771  1   1.9677  0.198292    
## type           0.007561  1  19.3060  0.002306 ** 
## treatment:type 0.000056  1   0.1438  0.714371    
## Residuals      0.003133  8                       
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


########## %K
plant.K.sag<-lm(K~treatment*type, data=sage.nut)
Anova(plant.K.sag, type=3) # type and treatment
## Anova Table (Type III tests)
## 
## Response: K
##                 Sum Sq Df  F value    Pr(>F)    
## (Intercept)    12.5256  1 372.2328 5.404e-08 ***
## treatment       0.2563  1   7.6157   0.02469 *  
## type            0.1803  1   5.3571   0.04934 *  
## treatment:type  0.0736  1   2.1882   0.17733    
## Residuals       0.2692  8                       
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

posthoc<-emmeans(plant.K.sag, ~treatment)
multcomp::cld(posthoc, Letters=letters)
##  treatment emmean     SE df lower.CL upper.CL .group
##  unburned    1.61 0.0749  8     1.44     1.79  a    
##  burned      1.87 0.0749  8     1.70     2.04   b   
## 
## Results are averaged over the levels of: type 
## Confidence level used: 0.95 
## significance level used: alpha = 0.05 
## NOTE: If two or more means share the same grouping letter,
##       then we cannot show them to be different.
##       But we also did not show them to be the same.


########## %S
plant.S.sag<-lm(S~treatment*type, data=sage.nut)
Anova(plant.S.sag, type=3) # type effect
## Anova Table (Type III tests)
## 
## Response: S
##                 Sum Sq Df  F value    Pr(>F)    
## (Intercept)    0.67783  1 859.3665 1.986e-09 ***
## treatment      0.00010  1   0.1321    0.7257    
## type           0.11152  1 141.3891 2.299e-06 ***
## treatment:type 0.00039  1   0.4885    0.5044    
## Residuals      0.00631  8                       
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


############## Zn ppm
plant.ZN.sag<-lm(ZN~treatment*type, data=sage.nut)
Anova(plant.ZN.sag, type=3) #no effect
## Anova Table (Type III tests)
## 
## Response: ZN
##                 Sum Sq Df F value   Pr(>F)   
## (Intercept)    19959.4  1 15.1723 0.004576 **
## treatment       3073.6  1  2.3364 0.164903   
## type            3280.7  1  2.4938 0.152947   
## treatment:type  1236.3  1  0.9398 0.360731   
## Residuals      10524.1  8                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

posthoc<-emmeans(plant.ZN.sag, ~treatment| type)
multcomp::cld(posthoc, Letters=letters)
## type = leaf:
##  treatment emmean   SE df lower.CL upper.CL .group
##  unburned    36.3 20.9  8    -12.0     84.6  a    
##  burned      81.6 20.9  8     33.3    129.9  a    
## 
## type = stem:
##  treatment emmean   SE df lower.CL upper.CL .group
##  unburned    30.1 20.9  8    -18.2     78.4  a    
##  burned      34.8 20.9  8    -13.5     83.1  a    
## 
## Confidence level used: 0.95 
## significance level used: alpha = 0.05 
## NOTE: If two or more means share the same grouping letter,
##       then we cannot show them to be different.
##       But we also did not show them to be the same.

###############################################
###############################################
### Willow ### 
######### %N
plant.N.wil<-lm(N~treatment*type, data=will.nut)
Anova(plant.N.wil, type=3) #  main effects
## Anova Table (Type III tests)
## 
## Response: N
##                Sum Sq Df  F value    Pr(>F)    
## (Intercept)    8.7381  1 644.0658 3.766e-08 ***
## treatment      0.0817  1   6.0194   0.04388 *  
## type           1.4538  1 107.1530 1.703e-05 ***
## treatment:type 0.0436  1   3.2119   0.11620    
## Residuals      0.0950  7                       
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


########## %P 
plant.P.wil<-lm(P~treatment*type, data=will.nut)
Anova(plant.P.wil, type=3) # type and treatment
## Anova Table (Type III tests)
## 
## Response: P
##                  Sum Sq Df  F value    Pr(>F)    
## (Intercept)    0.156865  1 447.9429 1.323e-07 ***
## treatment      0.006403  1  18.2834  0.003674 ** 
## type           0.007239  1  20.6703  0.002647 ** 
## treatment:type 0.000880  1   2.5131  0.156921    
## Residuals      0.002451  7                       
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

posthoc<-emmeans(plant.P.wil, ~treatment)
multcomp::cld(posthoc, Letters=letters)
##  treatment emmean      SE df lower.CL upper.CL .group
##  unburned   0.143 0.00764  7    0.125    0.161  a    
##  burned     0.190 0.00854  7    0.170    0.210   b   
## 
## Results are averaged over the levels of: type 
## Confidence level used: 0.95 
## significance level used: alpha = 0.05 
## NOTE: If two or more means share the same grouping letter,
##       then we cannot show them to be different.
##       But we also did not show them to be the same.


########## %K
plant.K.wil<-lm(K~treatment*type, data=will.nut)
Anova(plant.K.wil, type=3) # type and treatment
## Anova Table (Type III tests)
## 
## Response: K
##                Sum Sq Df  F value    Pr(>F)    
## (Intercept)    4.6128  1 548.0120  6.59e-08 ***
## treatment      0.0676  1   8.0344 0.0252428 *  
## type           0.2640  1  31.3583 0.0008161 ***
## treatment:type 0.0015  1   0.1725 0.6903484    
## Residuals      0.0589  7                       
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

posthoc<-emmeans(plant.K.wil, ~treatment)
multcomp::cld(posthoc, Letters=letters)
##  treatment emmean     SE df lower.CL upper.CL .group
##  unburned   0.817 0.0375  7    0.728    0.905  a    
##  burned     1.006 0.0419  7    0.906    1.105   b   
## 
## Results are averaged over the levels of: type 
## Confidence level used: 0.95 
## significance level used: alpha = 0.05 
## NOTE: If two or more means share the same grouping letter,
##       then we cannot show them to be different.
##       But we also did not show them to be the same.


########## %S
plant.S.wil<-lm(S~treatment*type, data=will.nut)
Anova(plant.S.wil, type=3) # main and interactions
## Anova Table (Type III tests)
## 
## Response: S
##                  Sum Sq Df  F value    Pr(>F)    
## (Intercept)    0.197633  1 1748.117 1.168e-09 ***
## treatment      0.002521  1   22.303  0.002151 ** 
## type           0.042375  1  374.819 2.446e-07 ***
## treatment:type 0.001355  1   11.985  0.010519 *  
## Residuals      0.000791  7                       
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

posthoc<-emmeans(plant.S.wil, ~treatment| type)
multcomp::cld(posthoc, Letters=letters)
## type = leaf:
##  treatment emmean      SE df lower.CL upper.CL .group
##  unburned  0.2157 0.00614  7   0.2012   0.2302  a    
##  burned    0.2567 0.00614  7   0.2422   0.2712   b   
## 
## type = stem:
##  treatment emmean      SE df lower.CL upper.CL .group
##  burned    0.0688 0.00752  7   0.0510   0.0865  a    
##  unburned  0.0728 0.00614  7   0.0583   0.0873  a    
## 
## Confidence level used: 0.95 
## significance level used: alpha = 0.05 
## NOTE: If two or more means share the same grouping letter,
##       then we cannot show them to be different.
##       But we also did not show them to be the same.

############## Zn ppm
plant.ZN.wil<-lm(ZN~treatment*type, data=will.nut)
Anova(plant.ZN.wil, type=3) #no effect
## Anova Table (Type III tests)
## 
## Response: ZN
##                Sum Sq Df  F value    Pr(>F)    
## (Intercept)    124440  1 196.4564 2.229e-06 ***
## treatment       22363  1  35.3043 0.0005748 ***
## type            21956  1  34.6631 0.0006071 ***
## treatment:type   5340  1   8.4306 0.0228697 *  
## Residuals        4434  7                       
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

posthoc<-emmeans(plant.ZN.wil, ~treatment| type)
multcomp::cld(posthoc, Letters=letters)
## type = leaf:
##  treatment emmean   SE df lower.CL upper.CL .group
##  unburned    81.6 14.5  7    47.21    115.9  a    
##  burned     203.7 14.5  7   169.31    238.0   b   
## 
## type = stem:
##  treatment emmean   SE df lower.CL upper.CL .group
##  unburned    35.8 14.5  7     1.44     70.2  a    
##  burned      68.4 17.8  7    26.32    110.5  a    
## 
## Confidence level used: 0.95 
## significance level used: alpha = 0.05 
## NOTE: If two or more means share the same grouping letter,
##       then we cannot show them to be different.
##       But we also did not show them to be the same.
plant.nut$int.fac<-factor(interaction(plant.nut$plant, plant.nut$type),
                         levels=c("sage.leaf", "sage.stem", "willow.leaf", "willow.stem"))
####### figures
N.plot<- ggplot(plant.nut, aes(x=int.fac, y=N, fill=treatment)) +
  geom_boxplot(alpha=0.7) +
  scale_fill_manual(values = c("brown1", "mediumseagreen")) +
  geom_dotplot(binaxis='y', stackdir='center', alpha=0.5, dotsize=0.5,
                 position=position_dodge(0.75))+
  xlab("Plant:Tissue")+
  ylab("%N")+
  theme_classic() +
  theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))

P.plot<- ggplot(plant.nut, aes(x=int.fac, y=P, fill=treatment)) +
  geom_boxplot(alpha=0.7) +
  scale_fill_manual(values = c("brown1", "mediumseagreen")) +
  geom_dotplot(binaxis='y', stackdir='center', alpha=0.5, dotsize=0.5,
                 position=position_dodge(0.75))+
  xlab("Plant:Tissue")+
  ylab("%P")+
  theme_classic() +
  theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))

K.plot<- ggplot(plant.nut, aes(x=int.fac, y=K, fill=treatment)) +
  geom_boxplot(alpha=0.7) +
  scale_fill_manual(values = c("brown1", "mediumseagreen")) +
  geom_dotplot(binaxis='y', stackdir='center', alpha=0.5, dotsize=0.5,
                 position=position_dodge(0.75))+
  xlab("Plant:Tissue")+
  ylab("%K")+
  theme_classic() +
  theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))


S.plot<- ggplot(plant.nut, aes(x=int.fac, y=S, fill=treatment)) +
  geom_boxplot(alpha=0.7) +
  scale_fill_manual(values = c("brown1", "mediumseagreen")) +
  geom_dotplot(binaxis='y', stackdir='center', alpha=0.5, dotsize=0.5,
                 position=position_dodge(0.75))+
  xlab("Plant:Tissue")+
  ylab("%S")+
  theme_classic() +
  theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))

Zn.plot<- ggplot(plant.nut, aes(x=int.fac, y=ZN, fill=treatment)) +
  geom_boxplot(alpha=0.7) +
  scale_fill_manual(values = c("brown1", "mediumseagreen")) +
  geom_dotplot(binaxis='y', stackdir='center', alpha=0.5, dotsize=0.5,
                 position=position_dodge(0.75)) +
  xlab("Plant:Tissue")+
  ylab("Zn ppm")+
  theme_classic() +
  theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))
  
extract.legend.nut <- get_legend(
  # create some space to the left of the legend
  Zn.plot + theme(legend.box.margin = margin(0, 0, 0, 10)))

nutrients<-plot_grid(
  N.plot+ theme(legend.position = "none"),
  P.plot+ theme(legend.position = "none"),
  K.plot+ theme(legend.position = "none"), 
  S.plot+ theme(legend.position = "none"), 
  Zn.plot+ theme(legend.position = "none"),
  extract.legend.nut, 
  rel_widths = c(8,8,8,8,8,3), ncol=6)

nutrients
**Figure** Elemental analysis of burned and unburned plant material (leaves and stem) from sage and willow prior to being added to experimental treatments.

Figure Elemental analysis of burned and unburned plant material (leaves and stem) from sage and willow prior to being added to experimental treatments.

ggsave("figures/leaf.nutrients.pdf", height=4, width=12)

H2O Phosphorus

The phosphorous concntration (total dissolved phosphorus (TDP)) in water was only run at Time-2 (Day-31). Water was collected from each tank, and filtered using a GF/F.

  • We will make a plot of the raw data and run the model fitting, with smoother contrasts.
phos<-read.csv("data/Pyro_water.phosph.csv")

fac2<-c("Time.Point", "Treatment", "Tank") # make factors
phos[fac2]<-lapply(phos[fac2],factor)

phos<-na.omit(phos)

############# phosphorous T2: significant smoothers, not treatment overall
m1.T2.phos<- gam(TP.umol..l ~ Treatment +
            s(plant.mass..g, by=Treatment), data=phos, method="REML", family="gaussian")

m2.T2.phos<- gam(TP.umol..l ~ Treatment +
            s(plant.mass..g), data=phos, method="REML", family="gaussian")

m3.T2.phos<- gam(TP.umol..l ~
            s(plant.mass..g), data=phos, method="REML", family="gaussian")

AIC.T2.phos<-AIC(m1.T2.phos,m2.T2.phos, m3.T2.phos)
# factor smooth best

summary(m1.T2.phos)
anova.gam(m1.T2.phos)
gam.check(m1.T2.phos, rep=1000)
draw(m1.T2.phos)
concrvity(m1.T2.phos)
par(mfrow = c(1, 2))
plot(m1.T2.phos, all.terms = TRUE, page=1)

# model predictions
phos.diff.T2<-plot_difference(
  m1.T2.phos,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

## AIC table
mod.phos<-rep(c("Treatment + s(plant.mass..g, by=Treatment)", 
              "Treatment + s(plant.mass..g)", 
              "s(plant.mass..g)"), times=1)

mod.phos.df<- data.frame(mod.phos)

AIC.phos.mod<-cbind(mod.phos.df, AIC.T2.phos)
write.csv(AIC.phos.mod, "output/AIC models/AIC.phos.mod.csv")

Table: Results for total phosphorous across burned/unburned treatments at Day-31.

anova.gam(m1.T2.phos)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## TP.umol..l ~ Treatment + s(plant.mass..g, by = Treatment)
## 
## Parametric Terms:
##           df     F p-value
## Treatment  1 1.329   0.267
## 
## Approximate significance of smooth terms:
##                                      edf Ref.df     F p-value
## s(plant.mass..g):Treatmentburned   2.924  3.525 154.7  <2e-16
## s(plant.mass..g):Treatmentunburned 2.930  3.371 124.6  <2e-16


###########  
#plot for the model output on rawdata
phos.T2.mod.plot<-
  plot_smooths(
  model = m1.T2.phos,
  series = plant.mass..g,
  comparison = Treatment
)  + theme(legend.position = "none") +
  geom_point(data=phos, 
             aes(x=plant.mass..g, y=TP.umol..l, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +
  ylab(expression(paste("TP", ~(mu*mol/L), sep=""))) +
  xlab("plant material (g)") +
  ggtitle("Time-2") +
  coord_cartesian(ylim=c(0, 50)) +
  Fig.formatting +
  theme(legend.key.size = unit(1,"line"))


phos.plots<-plot_grid(phos.T2.mod.plot, phos.diff.T2, ncol=2,  rel_widths = c(8, 5), 
                      labels=c('A', 'B'), label_size=8)

phos.plots
**Figure** (**A**) Total phosphorus concentration in water from burned and unburned treatments at Day-31, and (**B**) the difference between burned and unburned treatment smoothers.

Figure (A) Total phosphorus concentration in water from burned and unburned treatments at Day-31, and (B) the difference between burned and unburned treatment smoothers.

ggsave("figures/phos.plots.pdf", height=5, width=8)

Greenhouse Gas Data

Samples for carbon dioxide (CO2) and methane (CH4) greenhouse gasses were collected from each tank on Days-0, 10, 31 and 59 of the experiment using the headspace method. Background concentrations of CO2 and CH4 in ambient air were collected at each sampling day by collecting 12 mL of air in evacuated Exetainers.

GHG<-read.csv("data/GH.gases/Pyro_ghg_headspace.csv")
GHG<-na.omit(GHG) # remove NAs

# set structure
make.fac<-c("Time.point", "Treatment", "Tank", "Gas")
GHG[make.fac] <- lapply(GHG[make.fac], factor) # make all these factors
GHG$plant.mass..g<-as.numeric(GHG$plant.mass..g)

# rename
GHG<- GHG %>% rename("GHG.nM" = "GHGwater..nmol.GHG..L.H2O")

# reorder columns and export
GHG<- GHG %>% select(Time.point, Treatment, plant.mass..g, Tank, Gas, GHG.nM)

GHG<-GHG[!(GHG$GHG.nM < 0),]
#### Make plots and run models for CO2

CO2<-subset(GHG, Gas=="CO2")

#convert GHG units from nM to uM
CO2$GHG.uM<- CO2$GHG.nM/1000

############# GHG plots and modesl
#### CO2
#######-- T0

m1.T0.CO2<- gam(GHG.uM ~ Treatment +
            s(plant.mass..g, by=Treatment), subset = Time.point=="T0", data = CO2,
            method="REML", family="gaussian")

m2.T0.CO2<- gam(GHG.uM ~ Treatment +
            s(plant.mass..g), subset = Time.point=="T0", data = CO2,
            method="REML", family="gaussian")

m3.T0.CO2<- gam(GHG.uM ~
            s(plant.mass..g), subset = Time.point=="T0", data = CO2,
            method="REML", family="gaussian")

CO2.T0.AIC<-AIC(m1.T0.CO2,m2.T0.CO2, m3.T0.CO2)
#factor smooth best

summary(m1.T0.CO2)
anova.gam(m1.T0.CO2)
gam.check(m1.T0.CO2, rep=1000)
draw(m1.T0.CO2)
concrvity(m1.T0.CO2)
par(mfrow = c(1, 2))
plot(m1.T0.CO2, all.terms = TRUE, page=1)

# model predictions
CO2.diff.T0<-plot_difference(
  m1.T0.CO2,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
#plot for the model output on rawdata
CO2.T0.mod.plot<-
  plot_smooths(
  model = m1.T0.CO2,
  series = plant.mass..g,
  comparison = Treatment
)  + theme(legend.position = "none") +
  geom_point(data=CO2[(CO2$Time.point=="T0"),], 
             aes(x=plant.mass..g, y=GHG.uM, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +
  ylab(expression(paste("CO"[2], ~(mu*M), sep=""))) +
  xlab("plant material (g)") +
  ggtitle("Time-0") +
  coord_cartesian(ylim=c(0, 400)) +
  Fig.formatting +
  theme(legend.key.size = unit(1,"line"))

CO2.T0.mod.plot

#### CO2 
#######-- T1

m1.T1.CO2<- gam(GHG.uM ~ Treatment +
            s(plant.mass..g, by=Treatment), subset = Time.point=="T1", data = CO2,
            method="REML", family="gaussian")

m2.T1.CO2<- gam(GHG.uM ~ Treatment +
            s(plant.mass..g), subset = Time.point=="T1", data = CO2,
            method="REML", family="gaussian")

m3.T1.CO2<- gam(GHG.uM ~
            s(plant.mass..g), subset = Time.point=="T1", data = CO2,
            method="REML", family="gaussian")


CO2.T1.AIC<-AIC(m1.T1.CO2,m2.T1.CO2, m3.T1.CO2)
#factor smooth best

summary(m1.T1.CO2)
anova.gam(m1.T1.CO2)
gam.check(m1.T1.CO2, rep=1000)
draw(m1.T1.CO2)
concrvity(m1.T1.CO2)
par(mfrow = c(1, 2))
plot(m1.T1.CO2, all.terms = TRUE, page=1)

# model predictions
CO2.diff.T1<-plot_difference(
  m1.T1.CO2,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
#plot for the model output on rawdata
CO2.T1.mod.plot<-
  plot_smooths(
  model = m1.T1.CO2,
  series = plant.mass..g,
  comparison = Treatment
)  + theme(legend.position = "none") +
  geom_point(data=CO2[(CO2$Time.point=="T1"),], 
             aes(x=plant.mass..g, y=GHG.uM, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +
  ylab(expression(paste("CO"[2], ~(mu*M), sep=""))) +
  xlab("plant material (g)") +
  ggtitle("Time-1") +
  coord_cartesian(ylim=c(0, 400)) +
  Fig.formatting +
  theme(legend.key.size = unit(1,"line"))

CO2.T1.mod.plot

#### CO2
#######-- T2

m1.T2.CO2<- gam(GHG.uM ~ Treatment +
            s(plant.mass..g, by=Treatment), subset = Time.point=="T2", data = CO2,
            method="REML", family="gaussian")

m2.T2.CO2<- gam(GHG.uM ~ Treatment +
            s(plant.mass..g), subset = Time.point=="T2", data = CO2,
            method="REML", family="gaussian")

m3.T2.CO2<- gam(GHG.uM ~
            s(plant.mass..g), subset = Time.point=="T2", data = CO2,
            method="REML", family="gaussian")

CO2.T2.AIC<-AIC(m1.T2.CO2, m2.T2.CO2, m3.T2.CO2)
# smooth by factor best

summary(m1.T2.CO2)
anova.gam(m1.T2.CO2)
gam.check(m1.T2.CO2, rep=1000)
draw(m1.T2.CO2)
concrvity(m1.T2.CO2)
par(mfrow = c(1, 2))
plot(m1.T2.CO2, all.terms = TRUE, page=1)

# model predictions
CO2.diff.T2<-plot_difference(
  m1.T2.CO2,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
#plot for the model output on rawdata
CO2.T2.mod.plot<-
  plot_smooths(
  model = m1.T2.CO2,
  series = plant.mass..g,
  comparison = Treatment
)  + theme(legend.position = "none") +
  geom_point(data=CO2[(CO2$Time.point=="T2"),], 
             aes(x=plant.mass..g, y=GHG.uM, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +
  ylab(expression(paste("CO"[2], ~(mu*M), sep=""))) +
  xlab("plant material (g)") +
  ggtitle("Time-2") +
  coord_cartesian(ylim=c(0, 400)) +
  Fig.formatting +
  theme(legend.key.size = unit(1,"line"))

CO2.T2.mod.plot


#### CO2 
#######-- T3

m1.T3.CO2<- gam(GHG.uM ~ Treatment +
            s(plant.mass..g, by=Treatment), subset = Time.point=="T3", data = CO2,
            method="REML", family="gaussian")

m2.T3.CO2<- gam(GHG.uM ~ Treatment +
            s(plant.mass..g), subset = Time.point=="T3", data = CO2,
            method="REML", family="gaussian")

m3.T3.CO2<- gam(GHG.uM ~
            s(plant.mass..g), subset = Time.point=="T3", data = CO2,
            method="REML", family="gaussian")

CO2.T3.AIC<-AIC(m1.T3.CO2, m2.T3.CO2, m3.T3.CO2)
# smooth by factor best

summary(m1.T3.CO2)
anova.gam(m1.T3.CO2)
gam.check(m1.T3.CO2, rep=1000)
draw(m1.T3.CO2)
concrvity(m1.T3.CO2)
par(mfrow = c(1, 2))
plot(m1.T3.CO2, all.terms = TRUE, page=1)

# model predictions
CO2.diff.T3<-plot_difference(
  m1.T3.CO2,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
#plot for the model output on rawdata
CO2.T3.mod.plot<-
  plot_smooths(
  model = m1.T3.CO2,
  series = plant.mass..g,
  comparison = Treatment
)  + theme(legend.position = "none") +
  geom_point(data=CO2[(CO2$Time.point=="T3"),], 
             aes(x=plant.mass..g, y=GHG.uM, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +
  ylab(expression(paste("CO"[2], ~(mu*M), sep=""))) +
  xlab("plant material (g)") +
  ggtitle("Time-3") +
  coord_cartesian(ylim=c(0, 400)) +
  Fig.formatting +
  theme(legend.key.size = unit(1,"line"))

CO2.T3.mod.plot

# models and raw data
CO2.model.plots<-plot_grid(
  CO2.T0.mod.plot+ theme(legend.position= "none") + ggtitle( "Day-0"),
  CO2.T1.mod.plot+ theme(legend.position= "none") + ggtitle( "Day-10"),
  CO2.T2.mod.plot+ theme(legend.position= "none") + ggtitle( "Day-31"),
  CO2.T3.mod.plot+ theme(legend.position= "none") + ggtitle( "Day-59"),
  extract.legend, 
  rel_widths = c(8,8,8,8,3), ncol=5)

### model differences
CO2.plot.diff<-plot_grid(
  CO2.diff.T0+ ggtitle("CO2-T0"),
  CO2.diff.T1+ ggtitle("Day-10"),
  CO2.diff.T2+ ggtitle("Day-31"),
  CO2.diff.T3+ ggtitle("Day-59"),
  rel_widths = c(8,8,8,8), ncol=4)

## AIC table
mod.ghg<-rep(c("Treatment +s(plant.mass..g, by=Treatment)", 
              "Treatment + s(plant.mass..g)", 
              "s(plant.mass..g)"), times=4)

mod.ghg.df<- data.frame(mod.ghg)

AIC.CO2<-bind_rows(CO2.T0.AIC, CO2.T1.AIC, CO2.T2.AIC, CO2.T3.AIC)
AIC.CO2.mod<-cbind(mod.ghg.df, AIC.CO2)
write.csv(AIC.CO2.mod, "output/AIC models/AIC.CO2.mod.csv")

Table: Results for CO2 across burned/unburned treatments at Day-0.

anova.gam(m1.T0.CO2)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## GHG.uM ~ Treatment + s(plant.mass..g, by = Treatment)
## 
## Parametric Terms:
##           df     F  p-value
## Treatment  1 14.98 0.000776
## 
## Approximate significance of smooth terms:
##                                      edf Ref.df      F p-value
## s(plant.mass..g):Treatmentburned   1.000  1.000 10.566 0.00353
## s(plant.mass..g):Treatmentunburned 4.022  4.880  3.383 0.02381

Table: Results for CO2 across burned/unburned treatments at Day-10.

anova.gam(m1.T1.CO2)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## GHG.uM ~ Treatment + s(plant.mass..g, by = Treatment)
## 
## Parametric Terms:
##           df     F p-value
## Treatment  1 9.403 0.00547
## 
## Approximate significance of smooth terms:
##                                      edf Ref.df     F p-value
## s(plant.mass..g):Treatmentburned   2.047  2.527 157.7  <2e-16
## s(plant.mass..g):Treatmentunburned 2.966  3.633 144.2  <2e-16

Table: Results for CO2 across burned/unburned treatments at Day-31.

anova.gam(m1.T2.CO2)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## GHG.uM ~ Treatment + s(plant.mass..g, by = Treatment)
## 
## Parametric Terms:
##           df     F p-value
## Treatment  1 0.427    0.52
## 
## Approximate significance of smooth terms:
##                                      edf Ref.df     F p-value
## s(plant.mass..g):Treatmentburned   2.499  3.072 52.20  <2e-16
## s(plant.mass..g):Treatmentunburned 3.422  4.176 22.47  <2e-16

Table: Results for CO2 across burned/unburned treatments at Day-59.

anova.gam(m1.T3.CO2)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## GHG.uM ~ Treatment + s(plant.mass..g, by = Treatment)
## 
## Parametric Terms:
##           df     F p-value
## Treatment  1 2.341    0.14
## 
## Approximate significance of smooth terms:
##                                      edf Ref.df     F  p-value
## s(plant.mass..g):Treatmentburned   2.744  3.366 11.86 4.97e-05
## s(plant.mass..g):Treatmentunburned 1.000  1.000 28.09 2.26e-05

Now make plots and run models for methane.

CH4<-subset(GHG, Gas=="CH4")

m1.T0.CH4<- gam(GHG.nM ~ Treatment +
            s(plant.mass..g, by=Treatment), subset = Time.point=="T0", data = CH4,
            method="REML", family="gaussian")

m2.T0.CH4<- gam(GHG.nM ~ Treatment +
            s(plant.mass..g), subset = Time.point=="T0", data = CH4,
            method="REML", family="gaussian")

m3.T0.CH4<- gam(GHG.nM ~
            s(plant.mass..g), subset = Time.point=="T0", data = CH4,
            method="REML", family="gaussian")

CH4.T0.AIC<-AIC(m1.T0.CH4, m2.T0.CH4, m3.T0.CH4)
#factor single smooth best

summary(m2.T0.CH4)
anova.gam(m2.T0.CH4)
gam.check(m2.T0.CH4, rep=1000)
draw(m2.T0.CH4)
concrvity(m2.T0.CH4)
par(mfrow = c(1, 2))
plot(m2.T0.CH4, all.terms = TRUE, page=1)

# model predictions
CH4.diff.T0<-plot_difference(
  m2.T0.CH4,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
#plot for the model output on rawdata
CH4.T0.mod.plot<-
  plot_smooths(
  model = m2.T0.CH4,
  series = plant.mass..g,
  comparison=Treatment
)  + theme(legend.position = "none") +
  geom_point(data=CH4[(CH4$Time.point=="T0"),], 
             aes(x=plant.mass..g, y=GHG.nM, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +
  geom_line(aes(fill=Treatment, linetype=Treatment)) +
  ylab(expression(paste("CH"[4], ~(nM), sep=""))) +
  xlab("plant material (g)") +
  ggtitle("Time-0") +
  coord_cartesian(ylim=c(0, 50)) +
  Fig.formatting +
  theme(legend.key.size = unit(1,"line"))

CH4.T0.mod.plot

#### CH4 
#######-- T1

m1.T1.CH4<- gam(GHG.nM ~ Treatment +
            s(plant.mass..g, by=Treatment), subset = Time.point=="T1", data = CH4,
            method="REML", family="gaussian")

m2.T1.CH4<- gam(GHG.nM ~ Treatment +
            s(plant.mass..g), subset = Time.point=="T1", data = CH4,
            method="REML", family="gaussian")

m3.T1.CH4<- gam(GHG.nM ~
            s(plant.mass..g), subset = Time.point=="T1", data = CH4,
            method="REML", family="gaussian")

CH4.T1.AIC<-AIC(m1.T1.CH4, m2.T1.CH4, m3.T1.CH4)
#factor by smooth best

summary(m1.T1.CH4)
anova.gam(m1.T1.CH4)
gam.check(m1.T1.CH4, rep=1000)
draw(m1.T1.CH4)
concrvity(m1.T1.CH4)
par(mfrow = c(1, 2))
plot(m1.T1.CH4, all.terms = TRUE, page=1)

# model predictions
CH4.diff.T1<-plot_difference(
  m1.T1.CH4,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
#plot for the model output on rawdata
CH4.T1.mod.plot<-
  plot_smooths(
  model = m1.T1.CH4,
  series = plant.mass..g,
  comparison = Treatment
)  + theme(legend.position = "none") +
  geom_point(data=CH4[(CH4$Time.point=="T1"),], 
             aes(x=plant.mass..g, y=GHG.nM, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +
  ylab(expression(paste("CH"[4], ~(mu*M), sep=""))) +
  xlab("plant material (g)") +
  ggtitle("Time-1") +
  coord_cartesian(ylim=c(0, 50)) +
  Fig.formatting +
  theme(legend.key.size = unit(1,"line"))

CH4.T1.mod.plot

#### CH4
#######-- T2

m1.T2.CH4<- gam(GHG.nM ~ Treatment +
            s(plant.mass..g, by=Treatment), subset = Time.point=="T2", data = CH4,
            method="REML", family="gaussian")

m2.T2.CH4<- gam(GHG.nM ~ Treatment +
            s(plant.mass..g), subset = Time.point=="T2", data = CH4,
            method="REML", family="gaussian")

m3.T2.CH4<- gam(GHG.nM ~
            s(plant.mass..g), subset = Time.point=="T2", data = CH4,
            method="REML", family="gaussian")

CH4.T2.AIC<-AIC(m1.T2.CH4, m2.T2.CH4, m3.T2.CH4)
# global best

summary(m3.T2.CH4)
anova.gam(m3.T2.CH4)
gam.check(m3.T2.CH4, rep=1000)
draw(m3.T2.CH4)
concrvity(m3.T2.CH4)
par(mfrow = c(1, 2))
plot(m3.T2.CH4, all.terms = TRUE, page=1)

# model predictions
CH4.diff.T2<-plot_difference(
  m1.T2.CH4,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
#plot for the model output on rawdata
CH4.T2.mod.plot<-
  plot_smooths(
  model = m3.T2.CH4,
  series = plant.mass..g,
)  + theme(legend.position = "none") +
  geom_point(data=CH4[(CH4$Time.point=="T2"),], 
             aes(x=plant.mass..g, y=GHG.nM, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +
  ylab(expression(paste("CH"[4], ~(mu*M), sep=""))) +
  xlab("plant material (g)") +
  ggtitle("Time-2") +
  coord_cartesian(ylim=c(0, 50)) +
  Fig.formatting +
  theme(legend.key.size = unit(1,"line"))

CH4.T2.mod.plot


#### CH4 
#######-- T3

m1.T3.CH4<- gam(GHG.nM ~ Treatment +
            s(plant.mass..g, by=Treatment), subset = Time.point=="T3", data = CH4,
            method="REML", family="gaussian")

m2.T3.CH4<- gam(GHG.nM ~ Treatment +
            s(plant.mass..g), subset = Time.point=="T3", data = CH4,
            method="REML", family="gaussian")

m3.T3.CH4<- gam(GHG.nM ~
            s(plant.mass..g), subset = Time.point=="T3", data = CH4,
            method="REML", family="gaussian")

CH4.T3.AIC<-AIC(m1.T3.CH4, m2.T3.CH4, m3.T3.CH4)
# global with treatment best

summary(m2.T3.CH4)
anova.gam(m2.T3.CH4)
gam.check(m2.T3.CH4, rep=1000)
draw(m2.T3.CH4)
concrvity(m2.T3.CH4)
par(mfrow = c(1, 2))
plot(m2.T3.CH4, all.terms = TRUE, page=1)

# model predictions
CH4.diff.T3<-plot_difference(
  m1.T3.CH4,
  series = plant.mass..g,
  difference = list(Treatment = c("burned", "unburned"))
)

###########  
#plot for the model output on rawdata
CH4.T3.mod.plot<-
  plot_smooths(
  model = m2.T3.CH4,
  series = plant.mass..g,
  comparison=Treatment
)  + theme(legend.position = "none") +
  geom_point(data=CH4[(CH4$Time.point=="T3"),], 
             aes(x=plant.mass..g, y=GHG.nM, color=Treatment)) +
  scale_color_manual(values = c("brown1", "mediumseagreen")) +
  geom_line(aes(fill=Treatment, linetype=Treatment)) +
  ylab(expression(paste("CH"[4], ~(nM), sep=""))) +
  xlab("plant material (g)") +
  ggtitle("Time-3") +
  coord_cartesian(ylim=c(0, 50)) +
  Fig.formatting +
  theme(legend.key.size = unit(1,"line"))


CH4.model.plots<-plot_grid(
  CH4.T0.mod.plot+ theme(legend.position= "none") + ggtitle( "Day-0"),
  CH4.T1.mod.plot+ theme(legend.position= "none") + ggtitle( "Day-10"),
  CH4.T2.mod.plot+ theme(legend.position= "none") + ggtitle( "Day-31"),
  CH4.T3.mod.plot+ theme(legend.position= "none") + ggtitle( "Day-59"), 
  extract.legend, 
  rel_widths = c(8,8,8,8,3), ncol=5)

### model differences
CH4.plot.diff<-plot_grid(
  CH4.diff.T0+ ggtitle("CH4-Day-0"),
  CH4.diff.T1+ ggtitle("Day-10"),
  CH4.diff.T2+ ggtitle("Day-31"),
  CH4.diff.T3+ ggtitle("Day-59"),
  rel_widths = c(8,8,8,8), ncol=4)


##### AIC table
AIC.CH4<-bind_rows(CH4.T0.AIC, CH4.T1.AIC, CH4.T2.AIC, CH4.T3.AIC)

AIC.CH4.mod<-cbind(mod.ghg.df, AIC.CH4)
write.csv(AIC.CH4.mod, "output/AIC models/AIC.CH4.mod.csv")

Table: Results for CH4 across burned/unburned treatments at Day-0.

anova.gam(m2.T0.CH4)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## GHG.nM ~ Treatment + s(plant.mass..g)
## 
## Parametric Terms:
##           df     F p-value
## Treatment  1 2.038   0.166
## 
## Approximate significance of smooth terms:
##                  edf Ref.df     F p-value
## s(plant.mass..g)   1      1 0.718   0.405

Table: Results for CH4 across burned/unburned treatments at Day-10.

anova.gam(m1.T1.CH4)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## GHG.nM ~ Treatment + s(plant.mass..g, by = Treatment)
## 
## Parametric Terms:
##           df     F p-value
## Treatment  1 0.266   0.611
## 
## Approximate significance of smooth terms:
##                                      edf Ref.df    F p-value
## s(plant.mass..g):Treatmentburned   1.813  2.244 0.89 0.42743
## s(plant.mass..g):Treatmentunburned 3.346  4.086 6.53 0.00119

Table: Results for CH4 across burned/unburned treatments at Day-31.

anova.gam(m3.T2.CH4)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## GHG.nM ~ s(plant.mass..g)
## 
## Approximate significance of smooth terms:
##                    edf Ref.df    F p-value
## s(plant.mass..g) 1.000  1.001 0.19   0.667

Table: Results for CH4 across burned/unburned treatments at Day-59.

anova.gam(m2.T3.CH4)
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## GHG.nM ~ Treatment + s(plant.mass..g)
## 
## Parametric Terms:
##           df     F p-value
## Treatment  1 3.645   0.068
## 
## Approximate significance of smooth terms:
##                    edf Ref.df     F p-value
## s(plant.mass..g) 3.381  4.127 2.038   0.113

Compile the greenhouse gas plots for CO2 and CH4. Fit the data with model fitting

GHG.plots<-plot_grid(CO2.model.plots, CH4.model.plots, ncol=1, labels=c('A', 'B'), label_size=8)
GHG.plots
**Figure** Greenhouse gas concentration for (**A**) carbon dioxide (CO~2~) and (**B**) methane (CH~4~) at the beginning of the study before plant material was added (Day-0) and across three experimental time points.

Figure Greenhouse gas concentration for (A) carbon dioxide (CO2) and (B) methane (CH4) at the beginning of the study before plant material was added (Day-0) and across three experimental time points.

ggsave("figures/GHG.molar.mod.plots.pdf", height=7, width=12)
GHG.plot.diff<-plot_grid(CO2.plot.diff, CH4.plot.diff, ncol=1, labels=c('A', 'B'), label_size=8)
GHG.plot.diff
**Figure** Model effects from GAMs with differences between smoothers for greenhouse gasses (**A**) carbon dioxide (CO~2~) and (**B**) methane (CH~4~) in tanks receiving burned and unburned plant material at the beginning of the experiment and during three experimental time points.

Figure Model effects from GAMs with differences between smoothers for greenhouse gasses (A) carbon dioxide (CO2) and (B) methane (CH4) in tanks receiving burned and unburned plant material at the beginning of the experiment and during three experimental time points.

ggsave("figures/GHG.molar.mod.diff.pdf", height=7, width=12)